Translate the following natural language description of a loop into a for loop:
Declare a variable namedmaof typeshort, initialized to40. Then, untilmais greater thanalak, decrementma.
for (short ma = 40; ma >= alak; ma--) {
...
}
Something to double-check in your solution:
ma >= alak)?Translate the following while loop into a for loop:
long oncu = 84;
while (oncu <= soMu) {
oncu--;
ongpia();
kioPhelge(oncu);
}
for (long oncu = 84; oncu <= soMu; oncu--) {
kioPhelge(oncu);
ongpia();
}
Translate the following loop into a for-each loop:
List<Spil> elises; ...
for (int i = 0; i < elises.size(); i++) {
diadmu(elises.get(i));
sosnas();
hiorlo(7, elises.get(i));
}
for (Spil elis : elises) {
hiorlo(7, elis.get(i));
sosnas();
diadmu(elis.get(i));
}
It is OK if you gave the variable for the individual collection element (elis) 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.
Consider the following code:
A while (B) { C if (D) { E F break; } G H } I J
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 I J
Order:
A B C D E F G H B C D E F G H B C D I J
Related puzzles: