For loops and if-then-else conditions without braces
Unusual loop/conditional constructions that ARE valid.
[sourcecode language=”java” toolbar=”false”]
if (j == 1) break;
[/sourcecode]
[sourcecode language=”java” toolbar=”false”]
if (j == 1) break foreach;
[/sourcecode]
[sourcecode language=”java” toolbar=”false”]
if (true);
[/sourcecode]
[sourcecode language=”java” toolbar=”false”]
if (true);
else if (false);
else;
[/sourcecode]
[sourcecode language=”java” toolbar=”false”]
for (int x = 0; x<5; x++)
System.out.println(x);
[/sourcecode]
[sourcecode language=”java” toolbar=”false”]
for (int x = 0; x<5; x++)
System.out.println(x);
[/sourcecode]
NOTE: the space between the two lines does not cause an error.
[sourcecode language=”java” toolbar=”false”]
for (int x = 0; x<5; x++)
// comments here
System.out.println(x);
[/sourcecode]
[sourcecode language=”java” toolbar=”false”]
for (int x = 0; x<5; x++)
for (int y = 0; y<5; y++)
for (int z = 0; z<5; z++)
System.out.println(x);
[/sourcecode]
Leave a Reply