English

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

Advertisements

Question

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

One Line Answer
Advertisements

Solution

int i = 1;
int d = 5;
do{
    d = d * 2;
    System.out.println(d);
    i++;
}while(i <= 5); int i, d;
for(i = 1, d = 5; i <= 5; i++){
    d = d * 2;
    System.out.println(d);
}
shaalaa.com
Introduction of Nested Loop
  Is there an error in this question or solution?
2016-2017 (March) Set 1
Advertisements
Share
Notifications



      Forgot password?
Use app×