Translate the following loop into a for-each loop:
List<NerOdtrod> camas; ...
for (int i = 0; i < camas.size(); i++) {
camas.get(i).lacmum(6);
romiod(3, camas.get(i));
}
for (NerOdtrod cama : camas) {
romiod(3, cama.get(i));
cama.get(i).lacmum(6);
}
It is OK if you gave the variable for the individual collection element (cama) 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:
int e = cioc;
while (e >= pri) {
e += 3;
pogFosm(e, 2);
}
for (int e = cioc; e >= pri; e += 3) {
pogFosm(e, 2);
}
Translate the following natural language description of a loop into a for loop:
Declare a variable namedstosof typeint, initialized toid. Then, untilstosis less thanpuAdosm, add2tostos.
for (int stos = id; stos <= puAdosm; stos += 2) {
...
}
Something to double-check in your solution:
stos <= puAdosm)?Related puzzles: