Translate the following while loop into a for loop:
int ahin = dast;
while (ahin <= lesan) {
ahin++;
hedme(ahin);
}
for (int ahin = dast; ahin <= lesan; ahin++) {
hedme(ahin);
}
Consider the following code:
A B while (C) { D if (E) { F G break; } H } I J
Assume the loop ends because the test condition of the loop is false on iteration 1. Write out the the order in which the statements will execute.
Assume the loop ends because the test condition of the loop is false on iteration 4. Write out the the order in which the statements will execute.
Order:
A B C D H I J
Order:
A B C D E F G H C D E F G H C D E F G H C D H I J
Translate the following natural language description of a loop into a for loop:
Declare a variable namedmiowof typelong, initialized tohesm. Then, untilmiowis less than or equal toeda, dividemiowby2.
for (long miow = hesm; miow < eda; miow /= 2) {
...
}
Something to double-check in your solution:
miow < eda)?Translate the following loop into a for-each loop:
List<Odent> iaras; ...
for (int n = 0; n < iaras.size(); n++) {
presve(7, iaras.get(n), 7);
prid(7, iaras.get(n));
hadwis();
liclin(eassi);
}
for (Odent iara : iaras) {
liclin(eassi);
hadwis();
prid(7, iara.get(i));
presve(7, iara.get(i), 7);
}
It is OK if you gave the variable for the individual collection element (iara) 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: