Dear all,
I have some problems about Flow Control :
1. In The
Java Languange Specification 2nd Edition page 294-297 Section 14.13 The for Statement ....... there are statements that say :
If the ForInit part is not present, no action is taken (page 295 Section 14.13.1)
If the ForUpdate is not present, no action is taken (page 296 Section 14.13.2 and Section 14.13.3)
This is my code:
public class Loop
{
public static void main(
String[] args)
{
int i = 0;
for ( ; i<10; i++) // ForInit is not present
{
System.out.print( " " + i );
}
}
}
If I run, this code I get : 0 1 2 3 4 5 6 7 8 9
And
public class Loop
{
public static void main(String[] args)
{
for ( int i = 0; i< 10 ; ) // ForUpdate is not present
{
System.out.print( " " + i );
}
}
}
If I run, this code I get : 0 0 0 0 .... until ???
According to the statements, actually I don't have result when I run these code. What is the meaning of "no action is taken" ?
2. In The Java Languange Specification 2nd Edition page 291-294 Section 14.11 The while Statement and 14.12 The do Statement ....... there are statements that say :
If execution of the Statement completes abruptly because of a continue with no Label, then the entire while statement is executed again (page 292 Section 14.11.1)
If execution of the Statement completes abruptly because of a continue with no Label, then the Expression is evaluated. Then there is a choice based on the
resulting :
- If the value is true, then the entire do statement is executed again
- If the value is false, no further action is taken and the do statement completes normally
(page 239 Section 14.12.1)
This my code :
public class Loop
{
public static void main(String[] args)
{
int i = 0;
while (i<10)
{
System.out.print(" " + i);
i++;
if ( i == 5 )
{
continue;
}
}
}
}
If I run this code, I get : 0 1 2 3 4 5 6 7 8 9
And
public class Loop
{
public static void main(String[] args)
{
int i = 0;
do
{
System.out.print(" " + i);
i++;
if (i==5)
{
continue;
}
}
while (i<10);
}
}
If I run this code, I get: 0 1 2 3 4 5 6 7 8 9
According to the statements, actually I don't get that result so what is the meaning of "the entire do statement is executed again" and "the entire while statement is executed again"?
thx
daniel