# a while loop

• 11-11-2010, 03:55 PM
ile4
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:

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
• 11-11-2010, 04:03 PM
JosAH
Quote:

Originally Posted by ile4
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
• 11-11-2010, 04:10 PM
ile4
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?
• 11-11-2010, 04:19 PM
StormyWaters
Code:

```    while (x isn't big enough || b is less than a certain number) {           //do stuff...     }```
• 11-11-2010, 04:25 PM
ile4
Thanks a lot
• 11-11-2010, 04:37 PM
JosAH
Quote:

Originally Posted by StormyWaters
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
• 11-11-2010, 04:51 PM
StormyWaters
:eek: yep you are correct lol. I should have played closer attention. :p