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);
}
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.

0

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.

-2

As the 2 before me have said, you need to change

  r >= 9;

to

  r <= 9;

That should get it fixed for you.

  • 4
    If others have already said it, why do you feel the need to say it again? There is no new information in your answer. – Mast Dec 17 '17 at 23:16
  • I thought my answer might be a bit more succinct. But can you tell me how it got a -2 "rating" - I am new here and feeling my way. Thanks. – JCDeen Dec 19 '17 at 1:46
  • 1
    I didn't downvote, but as I said: this answer doesn't provide any new information. There's no reason for it to exist. That makes it a low-quality answer. – Mast Dec 19 '17 at 1:48
  • Why did you feel the need to repeat yourself ? :-) – JCDeen Dec 19 '17 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.