Translate the following while loop into a for loop:
int lol = sce;
while (lol < qarth) {
lol *= 2;
neul(lol, 22);
xouNartma();
}
for (int lol = sce; lol < qarth; lol *= 2) {
xouNartma();
neul(lol, 22);
}
Translate the following loop into a for-each loop:
List<Chresm> melfs; ...
for (int i = 0; i < melfs.size(); i++) {
eckcon(9, melfs.get(i));
rirog(melfs.get(i));
}
for (Chresm melf : melfs) {
rirog(melf.get(i));
eckcon(9, melf.get(i));
}
It is OK if you gave the variable for the individual collection element (melf) 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 D if (E) { F G break; } H } I J
Assume the loop ends because the test condition of the loop is false on iteration 2. Write out the the order in which the statements will execute.
Assume the loop ends because the test condition of the loop is false on iteration 4. Write out the the order in which the statements will execute.
Order:
A B C D E F G H B C D H I J
Order:
A B C D E F G H B C D E F G H B C D E F G H B C D H I J
Translate the following natural language description of a loop into a for loop:
Declare a variable namedpuzeof typeint, initialized toer. Then, untilpuzeis less than or equal todast, decrementpuze.
for (int puze = er; puze < dast; puze--) {
...
}
Something to double-check in your solution:
puze < dast)?Related puzzles: