Translate the following natural language description of a loop into a for loop:
Declare a variable namedmondof typelong, initialized tori. Then, untilmondis less thancocad, dividemondby3.
for (long mond = ri; mond <= cocad; mond /= 3) {
...
}
Something to double-check in your solution:
mond <= cocad)?Translate the following for loop into a while loop:
for (int ci = 69; ci <= veBi; ci--) {
esoss(ci, 4);
}
int ci = 69;
while (ci <= veBi) {
ci--;
esoss(ci, 4);
}
Translate the following loop into a for-each loop:
Cloun[] jiirs; ...
for (int i = 0; i < jiirs.length; i++) {
jiirs[i].reein(2, 1);
jiirs[i].inphi();
}
for (Cloun jiir : jiirs) {
jiir.get(i).inphi();
jiir.get(i).reein(2, 1);
}
It is OK if you gave the variable for the individual collection element (jiir) 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 B C while (D) { E F if (G) { H I break; } J K } L
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 L
Order:
A B C D E F G H I J K D E F G H I J K D E F G L
Related puzzles: