Help

Ok so i am currently having trouble with do while loop

heres a quick example
1
2
3
4
5
6
7
8
9
10
11
12
int valueA = 100;
int valueB = 100;

do
{

valueA = valueA - 100;

valueB = valueB - 50;

} while (valueA > 0) or (valueB > 0);


so obviously i am new to do while loops but basically what i want to accomplish is for after each loop it will evaluate both conditions and if one or the other meets the requirement of being or below 0 it will exit the loop. So for the example i posted above valueA would no longer be > 0 and the loop should end. In my actual work i thought something along the lines of this would work

1
2
3
4
5
6
7
8

do
{

....

}while ((valueA > 0) || (valueB > 0));


but it seems when i do this it will not exit the loop until both values are 0 or below.

any help or feedback would be appreciated
Last edited on
You use a logical OR. If any of the condition is true it will keep looping.
If you want to stop looping when one of the conditions become false, you have to use a logical AND (&&).
Thanks it works now. I think maybe I was just confusing myself
Topic archived. No new replies allowed.