Computer Applications
Convert the following for loop statement into the corresponding while loop and do-while loop:
int sum = 0;
for (int i = 0; i <= 50; i++)
sum = sum + i;
Java Iterative Stmts
11 Likes
Answer
while loop
int sum = 0, i = 0;
while (i <= 50) {
sum = sum + i;
i++;
}
do-while loop
int sum = 0, i = 0;
do {
sum = sum + i;
i++;
} while(i <= 50);
Answered By
3 Likes
Related Questions
What is an empty statement? Explain its usefulness.
How many times are the following loop bodies repeated? What is the final output in each case?
int x = 2; while (x < 20) if (x % 2 == 0) System.out.println(x);
Identify all the errors in the following repetitive statements.
while (x == y) { xx = yy; x = y; }
What are the differences between while loop and do-while loop?