mardi 26 janvier 2021

Java if-statement in for-loop

I have a couple booleans in my program and when the program runs only one is set to true (based on the input of the user in the console). Now my program has a basic for-loop which goes as follows: for(int i = 0; i < 5; i++){ do this}. But i want the "5" to change based on which boolean is true. something like if(boolean1 == true){ i < 5}else if(boolean2 == true){ i < 7}. How can this be achieved in java instead of writing a different for loop for every boolean?

Aucun commentaire:

Enregistrer un commentaire