Page 1 of 1

About Question com.enthuware.ets.scjp.v6.2.318 :

Posted: Mon Jun 25, 2012 1:26 am
by ETS User
Using a continue in a while loop causes the loop to break the current iteration and start the next iteration of the loop assuming that the while condition still holds true is possibly wrong. The while condition is always checked before entering in the while loop.

class TestClass
{
public static void main(String[] args)
{
Boolean flag = true;
while(flag){
System.out.println("A -> "+ flag );
flag = false;
System.out.println("B -> "+ flag );
if(flag==false)
continue;

System.out.println("C -> "+ flag );

}
}
}

Re: About Question com.enthuware.ets.scjp.v6.2.318 :

Posted: Mon Jun 25, 2012 11:49 am
by admin
You are right but it seems what the statement wants to convey is something like this:
"...start the next iteration of the loop. (Assuming that the while condition still holds true.)." It does not intend to mean that the while condition is assumed to be true always when a continue is encountered. It intends to mean that the next iteration is executed if the condition is true.

It is indeed badly worded and will be fixed asap.

thank you for your feedback!