# How to loop various conditions multiple times

I have 2 arrays (s_left and s_right) a length (dis), the arrays in reality are produced from sensor values.

The first situation entails looping the condition (s_left < dis) twice and at the same time looping (s_right < dis) once.

Is there a method to specify the number of times a individual condition can be looped through whilst preforming various conditions? The coding is in Java and I am not convinced the method attempted below is correct

public class test {
public void test() {
double s_right[] = new double[]{10, 13, 14, 15};
double s_left[] = new double[]{12.6, 14, 18, 18};

double dis = 12.5;

for (int i = 0; i < s_left.length; i++) {
if (s_left[i] < dis) {
for (int j = 0; j < s_left.length; j++) {
if ((s_left[j] < dis) && (s_right[i] < dis)) {
System.out.println("working!!!");
}

}
}
}
}
}
• what are you trying to do? – jsotola Mar 18 '20 at 17:44
• make the first comparison if ((s_left[i] < dis) && (s_right[i] < dis)) { ..... make the second comparison if (s_left[j] < dis) { – jsotola Mar 18 '20 at 17:49
• So, I am trying to preform.... if (s_left[j] < dis) ....twice and at the same time preform the loop.... if (s_right[i] < dis).... twice, upon looping and verifying the loop statement is shall print ....System.out.println("working!!!");.....Hope this makes sence? – Neamus Mar 18 '20 at 18:32
• This was my first attempt, I looped the (s_left[j] < dis) once then within the condition looped again but I think this will not work. the purpose is to verify the (s_left[j] < dis) twice before making the robot commence on its path. Same idea with the right side. – Neamus Mar 18 '20 at 20:23
• @jsotola would you have any idea how to run the loop twice before making the robot move forward? – Neamus Mar 18 '20 at 20:25