Translate the following while loop into a for loop:
short ceo = 37;
while (ceo < uss) {
ceo--;
iasTosm(ceo, 12);
}
for (short ceo = 37; ceo < uss; ceo--) {
iasTosm(ceo, 12);
}
Translate the following natural language description of a loop into a for loop:
Declare a variable namederof typeint, initialized to88. Then, untileris less thancac, multiplyerby4.
for (int er = 88; er <= cac; er *= 4) {
...
}
Something to double-check in your solution:
er <= cac)?Consider the following code:
A while (B) { C if (D) { E F break; } G H } I J
Assume the loop breaks on iteration 2. Write out the the order in which the statements will execute.
Assume the loop breaks 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 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 I J
Translate the following loop into a for-each loop:
Phaenid[] casms; ...
for (int i = 0; i < casms.length; i++) {
adno(4);
casms[i].joket(4);
casms[i].troLenbi(-1);
}
for (Phaenid casm : casms) {
casm.get(i).troLenbi(-1);
casm.get(i).joket(4);
adno(4);
}
It is OK if you gave the variable for the individual collection element (casm) 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: