Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualAshaman73

Posted 03 October 2012 - 11:41 PM

Sure, you could use break to exit the loop, but if your teacher don't like it (it is infact essentially a goto), then your second is almost right:

[source lang="java"]int i;boolean foundEmptyStrip = false;for (int i = 0; i < airstripArray.size() && foundEmptyStrip != true; i++ ) { if (airstripArray[i].getPlane == null) { airstripArray[i].addPlane(plane); foundEmptyStrip = true; }}if(i== airstripArray.size() ){ System.out.println("There are no empty airstrips");}[/source]

#1Ashaman73

Posted 03 October 2012 - 11:40 PM

Sure, you got use break to exit the loop, but if your teacher don't like it (it is infact essentially a goto), then your second is almost right:
[source lang="java"]int i;boolean foundEmptyStrip = false;for (int i = 0; i < airstripArray.size() && foundEmptyStrip != true; i++ ) { if (airstripArray[i].getPlane == null) { airstripArray[i].addPlane(plane); foundEmptyStrip = true; }}if(i== airstripArray.size() ){ System.out.println("There are no empty airstrips");}[/source]

PARTNERS