+ 1
instead of break
for a for loop in java, what can be used as an alternative to break?
8 Réponses
+ 2
You could change the loop statement variable, to make it stop in next iteration, but other than that, no...
Java removed "goto", because they though of it as "useless". How sad. 😔
+ 1
There is no other equivalent keyword of break. What are you trying to achieve that break cannot be used?
+ 1
If your for loop is in a function you could use "return" but that exits the for loop AND the function.
+ 1
Aleksei Radchenkov oh okay, thank you for the help!
+ 1
snaj,
No problem 👍
And happy learning!
0
CarrieForle I am trying to find an object in a partially filled array by using a for loop. Once found, I can exit the loop. We’ve been asked not to use break.
0
Aleksei Radchenkov what is a loop statement variable?
0
snaj , by loop variable I mean the variable which you use for comparison for your loop.