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
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