Hi, i have a simple question regarding the do whle loop using teensy board.
Using the code above, Serial monitor displays 0-4, but when i move the do while code inside void loop, it continues to run the program even after x=5
I don't know what I'm doing wrong with my simple test code for do while loop
Code:
int x;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
do {
Serial.println(x);
x++;
delay(1000);
} while (x < 5);
}
void loop() {
// put your main code here, to run repeatedly:
}
Using the code above, Serial monitor displays 0-4, but when i move the do while code inside void loop, it continues to run the program even after x=5
Code:
int x;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
do {
Serial.println(x);
x++;
delay(1000);
} while (x < 5);
}
I don't know what I'm doing wrong with my simple test code for do while loop