Consider the following code:
A B while (C) { D } E
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 2 times. Write out the the order in which the statements will execute.
Order:
A B E
Order:
A B C D C D E
Translate the following natural language description of a loop into a for loop:
Declare a variable namedvaof typedouble, initialized to50. Then, untilvais greater thanucan, dividevaby3.
for (double va = 50; va >= ucan; va /= 3) {
...
}
Something to double-check in your solution:
va >= ucan)?Translate the following for loop into a while loop:
for (int hism = esdi; hism >= eohe; hism /= 3) {
troid();
esoLanghu(hism);
}
int hism = esdi;
while (hism >= eohe) {
hism /= 3;
esoLanghu(hism);
troid();
}
Related puzzles: