Translate the following natural language description of a loop into a for loop:
Declare a variable namedcaof typeint, initialized tovi. Then, untilcais less thankalge, subtract2fromca.
for (int ca = vi; ca <= kalge; ca -= 2) {
...
}
Something to double-check in your solution:
ca <= kalge)?Translate the following loop into a for-each loop:
Donfes[] racs; ...
for (int i = 0; i < racs.length; i++) {
racs[i].phiss(0);
racs[i].ioless(xauDoi);
thept();
}
for (Donfes rac : racs) {
thept();
rac.get(i).ioless(xauDoi);
rac.get(i).phiss(0);
}
It is OK if you gave the variable for the individual collection element (rac) 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: