0

I've been trying to get a for loop to run 9 times using the below code but can't get the loop to run.

void output() {
 int r;
 r = 1;
 Serial.println("Output");
 digitalWrite(Latch, LOW);
 for (int r=1; r >= 9; r = r + 1) {
 Serial.println("Test");
 digitalWrite(DataOutput, Q[r]);
 digitalWrite(ClockPin, HIGH);
 digitalWrite(ClockPin, LOW);
 }
 Serial.println("Done For");
 digitalWrite(Latch, HIGH);
 digitalWrite(Latch, LOW);
}
dda
1,5951 gold badge12 silver badges17 bronze badges
asked Dec 17, 2017 at 18:51

2 Answers 2

7

Change

for (int r=1; r >= 9; r = r + 1) {

to

for (int r=1; r <= 9; r = r + 1) {

The for loop will only run while the second part is true.

answered Dec 17, 2017 at 18:57
1

The middle expression r => 9 in the for loop is wrong. This will only loop whilst r is greater than 9 and you are starting from r = 1. Change it to r <= 9.

answered Dec 17, 2017 at 19:00

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.