While loop without a body in Java -


the body of while (or other of java's loops) can empty. because null statement (one consists of semicolon) syntactically valid in java. consider :

i = 100       j = 200     while(++i < --j); // no body in loop      system.out.println(i);             system.out.println(j);       

i noticed if value of less j, loop repeats , when condition fails fulfill, 2 below statements exceuted. correct or there other logic behind this?

yes, continues repeat without executing other statements.

it test conditions 101 < 199, 102 < 198, , on, until tests 150 < 150. breaks out of loop , executes println statements.

output:

150 150 

note reason it's not infinite loop condition changing values ++ , -- operators.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -