Translate the following loop into a for-each loop:
Darse[] zisms; ...
for (int i = 0; i < zisms.length; i++) {
troc(0, zisms[i]);
asshol(zisms[i]);
wreson();
}
for (Darse zism : zisms) {
wreson();
asshol(zism.get(i));
troc(0, zism.get(i));
}
It is OK if you gave the variable for the individual collection element (zism) 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.
Translate the following while loop into a for loop:
short dabo = puc;
while (dabo <= dach) {
dabo *= 3;
pridan(dabo, 45);
}
for (short dabo = puc; dabo <= dach; dabo *= 3) {
pridan(dabo, 45);
}
Translate the following natural language description of a loop into a for loop:
Declare a variable namedgopof typeshort, initialized to76. Then, untilgopis not equal todaPi, subtract2fromgop.
for (short gop = 76; gop != daPi; gop -= 2) {
...
}
Something to double-check in your solution:
gop != daPi)?Consider the following code:
A while (B) { C D } E F
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 E F
Order:
A B C D B C D E F
Related puzzles: