KnowledgeBoat Logo

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