java - While Loop won't terminate? -
I'm using the loop for a while and when it will not end when it should be if it works correctly When it was done, it ends when randro
is either == highbound
or == low-end
.
The code of the loop:
do {do {randno = (int) (Math. (Math.rendum (* * 4)) + 0.5) -1) ; Direction = getDirection (Rendo, Heading); } While (robot. Approach (direction) == iarabot.wall); Println (randno); Println (highbound); Println (lowbound); Println ("---------------"); } While (randonne! = Cumound | randno! = Highbound);
The output is either 3 3 2 ------
, or 2 3 2 ------
, So the loop should end. The first loop ends properly (I try embedding it to work by trying them ...). What's going wrong?
Randonne! = Cummand | Randno! = HighBound
is always true, because randno
can not be the same as both less
and highbound
(assuming they are not
So if the loop does not end.
If you want to end, when P> If you want to end, when Edit: Based on your question, you want the second option. is different from both the ranges, then your position is lower Change in:
while (randno == lessbound || randno == highband)
rando
the same question One of the ranges is to change your position to:
while (randano! = Cumoundand randno! = Highband)
Comments
Post a Comment