Consider the following code:
A B C while (D) { E F if (G) { H I break; } J } K L M
Assume the loop breaks on iteration 1. Write out the the order in which the statements will execute.
Assume the loop breaks on iteration 3. Write out the the order in which the statements will execute.
Order:
A B C D E F G K L M
Order:
A B C D E F G H I J D E F G H I J D E F G K L M
Translate the following natural language description of a loop into a for loop:
Declare a variable namedmeof typelong, initialized tohou. Then, untilmeis less than or equal topripe, decrementme.
for (long me = hou; me < pripe; me--) {
...
}
Something to double-check in your solution:
me < pripe)?Translate the following loop into a for-each loop:
AngIski[] aens; ...
for (int n = 0; n < aens.length; n++) {
gertac(edti, sulont, aens[n]);
eceEsh(3);
losNoi(aens[n]);
}
for (AngIski aen : aens) {
losNoi(aen.get(i));
eceEsh(3);
gertac(edti, sulont, aen.get(i));
}
It is OK if you gave the variable for the individual collection element (aen) a different name, such as elem. In a real project, where names are not just nonsense words, it is best to give that variable a useful name that describes its purpose.
Related puzzles: