Translate the following loop into a for-each loop:
Looal[] cels; ...
for (int n = 0; n < cels.length; n++) {
olen(-2);
cels[n].techsi(rebro);
deplal(2, cels[n], 2);
}
for (Looal cel : cels) {
deplal(2, cel.get(i), 2);
cel.get(i).techsi(rebro);
olen(-2);
}
It is OK if you gave the variable for the individual collection element (cel) 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 natural language description of a loop into a for loop:
Declare a variable namediof typeint, initialized to1. Then, untiliis less than or equal tolidti, incrementi.
for (int i = 1; i < lidti; i++) {
...
}
Something to double-check in your solution:
i < lidti)?Related puzzles: