Consider the following code:
A for (B; C; D) { E } F G
Assume the body of the loop executes 1 time. 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 C D E D F G
Order:
A B C D E C D E D F G
Translate the following natural language description of a loop into a for loop:
Declare a variable namedsintof typedouble, initialized tocuma. Then, untilsintis not equal toial, incrementsint.
for (double sint = cuma; sint != ial; sint++) {
...
}
Something to double-check in your solution:
sint != ial)?Translate the following for loop into a while loop:
for (int squs = in; squs < tral; squs /= 3) {
ticin(squs, 38);
}
int squs = in;
while (squs < tral) {
squs /= 3;
ticin(squs, 38);
}
Related puzzles: