Java syntax: Difference between revisions

Content deleted Content added
m Type import declaration: added package - etc. Check this please.
Line 519:
 
===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.
 
====<code>while</code> loop====
In the <code>while</code> loop, the test is done before each iteration.
 
<source lang=Java5>
Line 531:
 
====<code>do ... while</code> loop====
In the <code>do ... while</code> loop, the test is done after each iteration. Consequently, the code is always executed at least once.
 
<source lang=Java5>
Line 541:
 
====<code>for</code> loop====
<code>for</code> loops in Java include an initializer, a condition and a counter expression. It is possible to include several expressions of the same kind using comma as delimiter (except in the condition). However, unlike C, the comma is just a delimiter and not an operator.
 
<source lang=Java5>
Line 554:
</source>
 
Like C, all three expressions are optional;. theThe following loop will beis infinite:
<source lang=Java5>
for (;;) {
Line 563:
====Enhanced <code>for</code> loop====
 
[[enhanced for loop|Enhanced <code>for</code> loop]]s have been available since [[J2SE 5.0]]. This type of loop uses built-in iterators over arrays and collections to return each item in the given collection. Every element will beis returned and reachable in the context of the code block. When the block has beenis executed, the next item will beis returned until there are no items remaining. Unlike [[C Sharp (programming language)|C#]], this kind of loop does not involve a special keyword, but instead uses a different notation style.
 
<source lang=Java5>