samedi 18 juillet 2020

Skipping To The Next if Statement from Inside a for Loop

I've been learning some Java in my spare time and I'm a beginner, so I'm very sorry if I don't understand some simple concepts. I've been trying to make a "Robot" move around an already made map. I've been trying to make lines of a text file into multiple arrays (ie. moving forward, turning left, turning right). Then, I've been trying to use values in those arrays to make the robot move. Basically, if the text file says:

1 0 0
0 1 0
0 0 1

So the first line is for moving, the second is for turning left and the third is for turning left. This is supposed to make the robot move, and then not turn. Then it moves on to the next column and doesn't move, turns left, and doesn't turn right. I'm trying to make sure it works no matter how long the code is. I'm able to put it into three arrays correctly, but I'm having trouble with this for loop. When the loop executes and the values are all 1's or above, it works perfectly. However, if any value is a 0, it completely exits the loop and the robot doesn't move. Any help or advice would be appreciated! Thank you!

Code is below:

public static void robotMove(Robot x) throws Exception {
  
     
     for (int i = 0; i < movedata.length; i++) {
     
        int y = movedata[i];
        int s = leftdata[i];
        int j = rightdata[i];
     
           for (int a = 0; a < movedata.length; a++) {
              
              if (y == 0) {
              //asking what to put here
              }
              else { 
                 again.Move(x, y);
              }
              
              if (s == 0) {
              //asking what to put here
              }
              else { 
                 again.Left(x, s);
              }
              
              if (j == 0) {
              //asking what to put here
              }
              else { 
                 again.Right(x, j);
              }
              
              
              
           }
     
     
     } 

Aucun commentaire:

Enregistrer un commentaire