cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
cutting for loops short
cutting for loops short
Nov 12, 2011 at 1:53am UTC
Blessman11
(370)
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?
Nov 12, 2011 at 2:35am UTC
mzimmers
(578)
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.
Nov 12, 2011 at 2:50am UTC
iFailed
(6)
you could try
for(int i = 0; (i <
list_length
||
condition_met
); i++)
{
statements
}
Nov 12, 2011 at 2:58am UTC
mzimmers
(578)
I think you mean:
for
(
int
i = 0; (i < list_length && condition_unmet); i++)
Nov 12, 2011 at 3:09am UTC
iFailed
(6)
yes^^
or make your statements increment i to meet the condition
Last edited on
Nov 12, 2011 at 3:10am UTC
Topic archived. No new replies allowed.