1. Member
Join Date
Nov 2010
Posts
24
Rep Power
0

a while loop

Hello

So I need a while loop, what I have are some fields:
An integer x, another integer b, a maximum limit, and a minimum limit (all ints).

What I need to do is:
When x is smaller than the minimum limit, I need to multiply x by 6, and add 2 to the integer b. I need to keep doing this, until x is between the minimum and maximum limits, then stop and print out the number.
I am confused how to do this.

What I have so far is this:

Java Code:
```while(x < minimum) {
x = x*6;
b = b + 2;
}```
I don't know how to make it stop when it's big enough though.
Any help would be much appreciated

2. Originally Posted by ile4
Java Code:
```while(x < minimum) {
x = x*6;
b = b + 2;
}```
I don't know how to make it stop when it's big enough though.
Any help would be much appreciated
It stops when x >= minimum, that's checked by your while condition.

kind regards,

Jos

3. Member
Join Date
Nov 2010
Posts
24
Rep Power
0
Thanks, okay I'm now supposed to add an extra bit which will stop the while loop either when x is big enough, or, when b reaches a certain number, (whichever is sooner). how can I do that?

4. Senior Member
Join Date
Feb 2009
Posts
312
Rep Power
8
Java Code:
```     while (x isn't big enough || b is less than a certain number) {
//do stuff...
}```

5. Member
Join Date
Nov 2010
Posts
24
Rep Power
0
Thanks a lot

6. Originally Posted by StormyWaters
Java Code:
```     while (x isn't big enough || b is less than a certain number) {
//do stuff...
}```
I don't think that is correct; the op wants to stop the loop when x is big enough or b is big enough; that check should be an &&, not a ||. (De Morgan's law).

kind regards,

Jos

7. Senior Member
Join Date
Feb 2009
Posts
312
Rep Power
8
:eek: yep you are correct lol. I should have played closer attention. :p

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•