Translate the following natural language description of a loop into a for loop:
Declare a variable namedraeof typeint, initialized to89. Then, untilraeis less thanelIckel, divideraeby2.
for (int rae = 89; rae <= elIckel; rae /= 2) {
...
}
Something to double-check in your solution:
rae <= elIckel)?Translate the following for loop into a while loop:
for (int vasi = 47; vasi < teSte; vasi *= 4) {
culer(vasi);
}
int vasi = 47;
while (vasi < teSte) {
vasi *= 4;
culer(vasi);
}
Translate the following loop into a for-each loop:
List<Uphi> iashs; ...
for (int n = 0; n < iashs.size(); n++) {
iashs.get(n).ossPren(5);
ghaDerdca(iashs.get(n));
}
for (Uphi iash : iashs) {
ghaDerdca(iash.get(i));
iash.get(i).ossPren(5);
}
It is OK if you gave the variable for the individual collection element (iash) 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 for (B; C; D) { E F } G H
Assume the body of the loop executes 0 times. Write out the the order in which the statements will execute.
Assume the body of the loop executes 3 times. Write out the the order in which the statements will execute.
Order:
A B D G H
Order:
A B C D E F C D E F C D E F D G H
Related puzzles: