dimanche 22 février 2015

Choose to loop infinitely if a number equals 0 or loop until some number if that number is greater than 0 - Java

I want to loop infinitely using a for loop if a number equals 0, and loop until that number number if the number is greater than 0. Here's the code to help visual what I'm getting at.



for (int i = 0; i < this.getNumRounds(); i++) {
// 30 some lines of code
}


or



for ( ; ; ) {
// 30 some lines of code
}


if getNumRounds() is greater than 0, do the first loop, if it equals 0, do the second. I would prefer to do this without copying and pasting my 30 some lines of code twice and using an if statement seeing as the code is redundant, though I could use a function to take out that redundancy, but I'm looking to see if there's another option.


Aucun commentaire:

Enregistrer un commentaire