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 <= 100; i++)
    sum = sum + i;

Java Iterative Stmts

5 Likes

Answer

while loop

int sum = 0, i = 0;
while (i <= 100)    {
    sum = sum + i;
    i++;
}

do-while loop

int sum = 0, i = 0;
do {
    sum = sum + i;
    i++;
} while(i <= 100);

Answered By

4 Likes


Related Questions