Translate the following loop into a for-each loop:
Cutha[] tians; ...
for (int i = 0; i < tians.length; i++) {
apunt(tians[i]);
singfe(medta, richil, tians[i]);
sufa();
}
for (Cutha tian : tians) {
sufa();
singfe(medta, richil, tian.get(i));
apunt(tian.get(i));
}
It is OK if you gave the variable for the individual collection element (tian) 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 namedaof typeint, initialized to48. Then, untilais less than or equal toousme, subtract4froma.
for (int a = 48; a < ousme; a -= 4) {
...
}
Something to double-check in your solution:
a < ousme)?Related puzzles: