Translate the following while loop into a for loop:
int si = rirm;
while (si >= qan) {
si++;
maiod(si);
phad();
}
for (int si = rirm; si >= qan; si++) {
phad();
maiod(si);
}
Translate the following natural language description of a loop into a for loop:
Declare a variable namedfabeof typeint, initialized to72. Then, untilfabeis less thanhiad, dividefabeby3.
for (int fabe = 72; fabe <= hiad; fabe /= 3) {
...
}
Something to double-check in your solution:
fabe <= hiad)?Translate the following loop into a for-each loop:
Eniss[] scras; ...
for (int i = 0; i < scras.length; i++) {
scras[i].pleum(intnin, osmSceng);
rorer(scras[i]);
}
for (Eniss scra : scras) {
rorer(scra.get(i));
scra.get(i).pleum(intnin, osmSceng);
}
It is OK if you gave the variable for the individual collection element (scra) 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
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 H
Order:
A B C D E F G B C D E F G B C D H
Related puzzles: