I have the following simple "for" loop:
void setup(){
Serial.begin(9600);
int i=0;
for(i=0;i<=4;i++);{
Serial.print(i);
}
}
void loop(){}
But when I watch the Serial Monitor, it only shows a "5." Why is it only running once?
I have the following simple "for" loop:
void setup(){
Serial.begin(9600);
int i=0;
for(i=0;i<=4;i++);{
Serial.print(i);
}
}
void loop(){}
But when I watch the Serial Monitor, it only shows a "5." Why is it only running once?
Solved it. The extra ";" at the end of the "for" line causes nothing to happen. When I remove it, like this, it works:
void setup(){
Serial.begin(9600);
int i=0;
for(i=0;i<4;i++){
Serial.println(i);
}
}
void loop(){}
The misplaced or missing semicolon.
You have just repeated an error that lives in history, the great SS7 telephone switch cascade failure of January 1990, causing a 9 hour long distance outage. It's origin was in a failure recovery routine where a missing semicolon caused failure through around 100 ESS4 switches. And being a recovery routine of course became an infinite loop of failure!
You have just repeated an error that lives in history, the great SS7 telephone switch cascade failure of January 1990,
That is interesting. Any information links to the event available on the web?
Lefty
But when I watch the Serial Monitor, it only shows a "5." Why is it only running once?
Actually, it didn't run just once. It ran 5 times. It just that each time did nothing except increment the value of i
and use a few cycles of processing time.
stick a
delay(1000);
in the code and you will see it count
@boffin1: you've missed the point - slowing the loop down will not show any numbers being printed, other than the terminal '5'.
You'll just have to wait longer to see it.
woops
yes I missed the point there, its in setup anyway
For hours of reading pleasure .... check Software Bugs - Software Glitches
NASA Mariner 1 , Venus probe
(period instead of comma in FORTRAN DO-Loop, 1962)
AT&T long distance service fails for nine hours
(Wrong BREAK statement in C-Code, 1990)
Rob
- AT&T long distance service fails for nine hours
(Wrong BREAK statement in C-Code, 1990)
This is great. I am going to quote this every time when somebody starts raving about how cool coding and computers are.