Simple "For" sketch will not run

I cannot get a simple "For" or "While" function to run on my Uno.
Here is the code for the example sketch I found.

int i;

void setup() {

Serial.begin(9600);
i=0;
for (i = 0; i < 10; i++) {
Serial.print("i = ");
Serial.println(i);
}
}

void loop() {
}

a) please use code tags.
b) what are the error messages shown when you try to upload or ‘run’ this code ?
c) is the serial monitor open at the correct speed ?


int i;

void setup() {

  Serial.begin(9600);
  i=0;
  for (i = 0; i < 10; i++) {
    Serial.print("i = ");
    Serial.println(i);
  }
}

void loop() {
}

No errors, baud is 9600, no output on serial monitor. Compiles and uploads fine, just no output.

Same problem when I try to run a "While" function.

After you get the serial monitor open and ready, press reset on your Arduino.

Hi,
What model Arduino controller are you using?
What Version IDE?

Your code works perfectly on my UNO.

Tom.. :smiley: :+1: :coffee: :australia:

Its an Uno and I have the latest IDE.

Pressed the reset and its working, don't know why.

Will try to run my big sketch again, that is what got me to this point in the first place. It would not run so I had to go back to the basics with this trial sketch. Tried both FOR and WHILE with no luck.

Thanks for the help,

John K

Hi, @john_kiedrowski

Great start, go back to basics, excellent approach. :+1: :+1: :+1: :+1: :+1:

Try RESET button on your main code.

Tom... :smiley: :+1: :coffee: :australia:

Move all your code to the loop() and try again

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.