Translate the following loop into a for-each loop:
List<Whilewn> edis; ...
for (int n = 0; n < edis.size(); n++) {
laeWaimp(1);
shiass(edis.get(n), -1);
edis.get(n).nicto();
}
for (Whilewn edi : edis) {
edi.get(i).nicto();
shiass(edi.get(i), -1);
laeWaimp(1);
}
It is OK if you gave the variable for the individual collection element (edi) 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 for loop into a while loop:
for (int pe = sul; pe <= ciTesh; pe--) {
enar(pe, 44);
}
int pe = sul;
while (pe <= ciTesh) {
pe--;
enar(pe, 44);
}
Consider the following code:
A B C while (D) { E } F G H
Assume the body of the loop executes 1 time. 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 B C D E F G H
Order:
A B C D E D E F G H
Translate the following natural language description of a loop into a for loop:
Declare a variable namedoof typeshort, initialized to27. Then, untilois not equal tomeof, incremento.
for (short o = 27; o != meof; o++) {
...
}
Something to double-check in your solution:
o != meof)?Related puzzles: