C++ and java loops are often written with empty bodies by placing all side effects into the tests, such as in the following two examples:
i = 0
while (a[i++] != 0);
for (i = 0; a[i] != 0; i++);
(a) Are these loops equivalent?
if a[0] is 0, the while loop will not run once. the for loop will run at least once
(b) Are there any advantages or disadvantages to using this style of code? Explain.
It makes it more concise, but can make it more difficult to read
No comments:
Post a Comment