Question:
Can you convert these loops into while/do- while loops in BlueJ?
S
2012-10-28 16:17:05 UTC
I am using a book to teach myself BlueJ, and am having problems with converting for-loops into while loops and do-while loops. I have two for loops and I want to convert one into a while loop and one into a do while loop. Can anyone do this?

I want to convert this into a while loop:

int t=500;
for(int r=1000;r<2500;r=r+20)
{
t+=r+10;
System.out.println(t);
}


I want to convert this into a do-while loop:

int x=0;
for(int y=1;y<=200;y++)
{
x=x*y;
}
Three answers:
Nunya
2012-10-28 16:24:08 UTC
int t=500;

for(int r=1000;r<2500;r=r+20)

{

t+=r+10;

System.out.println(t);

}



is the same as



int r=1000;

while(r<2500)

{

t+=r+10;

System.out.println(t);

r=r+20;

}

-----------------------------------------------------------------------

int x=0;

for(int y=1;y<=200;y++)

{

x=x*y;

}



is the same as



int y=1;

do

{

x=x*y;

y++;

}

while(y >= 200)
?
2016-12-28 13:34:47 UTC
attempt this: {     int x = 0, y = 0;     whilst (x < 3) {         whilst (y < 3) {             printf("*");             y++;         }         printf("n");         x++;     } }
?
2016-12-12 19:58:38 UTC
attempt this: {     int x = 0, y = 0;     at a similar time as (x < 3) {         at a similar time as (y < 3) {             printf("*");             y++;         }         printf("n");         x++;     } }


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...