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 is different from both the ranges, then your position is lower Change in:

P>

  while (randno == lessbound || randno == highband)  

If you want to end, when rando the same question One of the ranges is to change your position to:

  while (randano! = Cumoundand randno! = Highband)  

Edit: Based on your question, you want the second option.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -