Question about infinite loop and null terminator.

Hello, I've a question regarding the null terminator at the end of a loop without any statements, eg:
1
2
3
  while( n < 5); //notice the semicolon.
  //or
  for(int x; x<5; x++);


when I add the semicolon at the end, without any statements, does the loop execute infinitely? like "infinitely doing nothing"?
or does the loop stops right away when the null terminator is encountered?

thanks
The while loop runs infinitely if the condition is true, or never if the condition is false. The for loop will always finish. Since x must be initialized, if x < 5, it will eventually reach 5 from the increment. If x >= 5, the loop never runs.
oh i see, and yea, i forgot to initialize the local variable x to zero.
alright, thank you for the clarification.
It's easy to get tripped up by that. Consider:
1
2
3
4
do {
    ++n;
}
while (n < 5);

Now the line looks the same, but it's part of a do/while loop instead of a while loop.
Topic archived. No new replies allowed.