Computer Science, asked by ashessaha564gmailcom, 9 months ago

Convert following do-while loop into for loop.
int i = 1;
int d = 5;
do {
d = d * 2;
System.out.println(d);
i++;
} while(i <= 5);​

Answers

Answered by TrueAnswerer
8

int i = 1;

int d = 5;

do {

d = d * 2;

System.out.println(d);

i++;

} while(i <= 5);

For

for(int i = 1, d = 5; i<=5 ;i++){

d=d*2;

System.out.println(d);

}

Syntax of for loop

for (statement 1; statement 2; statement 3) {

// code block to be executed

}

Hope it helps

Similar questions