Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
what happens when semicolon comes after condition in while loop
Posted
Comments
Kornfeld Eliyahu Peter 22-Jul-14 7:24am    
Nothing...
[no name] 22-Jul-14 7:33am    
What happens you step through that code with a debugger?

1 solution

In the while loop (pseudo code)
C
while (<CONDITION>);

The empty statement is executed while the assertion <CONDITION> is non-zero, for instance

C
while (5);

is an infinite (empty) loop.


On the other hand, a semicolon is required after the while in the do-while loop, to close the statement:
C
do
  c = getchar();
while ( c != EOF );
 
Share this answer
 
Comments
Maciej Los 22-Jul-14 7:59am    
+5
CPallini 22-Jul-14 8:13am    
Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900