cutting for loops short

hi

How do you break out of a for loop if you were to meet the condition you wanted before if was over?

would you have to use the break operator like in while loops?
Yes, that will work. I'm not a fan of using break statements, though. While occasionally necessary, it's usually the sign of a logic design that could be improved. But, if you feel you must use it, go ahead.
you could try

for(int i = 0; (i < list_length || condition_met); i++)
{
statements
}
I think you mean:

for(int i = 0; (i < list_length && condition_unmet); i++)
yes^^
or make your statements increment i to meet the condition
Last edited on
Topic archived. No new replies allowed.