Content deleted Content added
(5 intermediate revisions by 2 users not shown) | |||
Line 476:
/* The following line is equivalent to
if (foo == ColorName.RED) foo = ColorName.BLUE; */
if (foo == RED) {
foo = BLUE; }
}
}
Line 722 ⟶ 724:
===Iteration statements===
Iteration statements are statements that are repeatedly executed when a given condition is evaluated as true. Since [[J2SE 5.0]], Java has four forms of such statements. The condition must have type <code>boolean</code> or <code>java.lang.Boolean
For example, the following code is valid in C but results in a compilation error in Java.
<syntaxhighlight lang="c">
while (1) {
doSomething();
}
</syntaxhighlight>
====<code>while</code> loop====
Line 763 ⟶ 768:
</syntaxhighlight>
Like C, all three expressions are optional. The following loop
<syntaxhighlight lang="java">
for (;;) {
Line 770 ⟶ 775:
</syntaxhighlight>
====
{{Main|
[[
<syntaxhighlight lang="java">
Line 783 ⟶ 788:
====Labels====
Labels are given points in code used by <code>break</code> and <code>continue</code> statements.
<syntaxhighlight lang="java">
|