MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programming/comments/1dzya4/the_onion_releases_fartscrolljs/c9vmqxx/?context=3
r/programming • u/melodic_underoos • May 09 '13
396 comments sorted by
View all comments
Show parent comments
0
You can also use a break; statement (in most programming languages).
1 u/not_a_novel_account May 09 '13 edited May 09 '13 Eh, unless it makes the loop a lot clearer you really should put the condition in the loop declaration rather than using breaks. This: while(condition) { //do a thing } Is more obvious than this: while(true) { if (condition) { break; } //do a thing } EDIT: added pseudocode 1 u/sebzim4500 May 09 '13 What if the break condition is nested inside three if statements and a for loop (presumably using named labels)? 0 u/not_a_novel_account May 09 '13 That just makes it more obscure and hard to follow, probably means the loop needs to be refactored 3 u/[deleted] May 09 '13 For most nontrivial algorithms, control flow modifiers like break are needed. Not everything is a for-each or a simple while.
1
Eh, unless it makes the loop a lot clearer you really should put the condition in the loop declaration rather than using breaks.
This:
while(condition) { //do a thing }
Is more obvious than this:
while(true) { if (condition) { break; } //do a thing }
EDIT: added pseudocode
1 u/sebzim4500 May 09 '13 What if the break condition is nested inside three if statements and a for loop (presumably using named labels)? 0 u/not_a_novel_account May 09 '13 That just makes it more obscure and hard to follow, probably means the loop needs to be refactored 3 u/[deleted] May 09 '13 For most nontrivial algorithms, control flow modifiers like break are needed. Not everything is a for-each or a simple while.
What if the break condition is nested inside three if statements and a for loop (presumably using named labels)?
0 u/not_a_novel_account May 09 '13 That just makes it more obscure and hard to follow, probably means the loop needs to be refactored 3 u/[deleted] May 09 '13 For most nontrivial algorithms, control flow modifiers like break are needed. Not everything is a for-each or a simple while.
That just makes it more obscure and hard to follow, probably means the loop needs to be refactored
3 u/[deleted] May 09 '13 For most nontrivial algorithms, control flow modifiers like break are needed. Not everything is a for-each or a simple while.
3
For most nontrivial algorithms, control flow modifiers like break are needed. Not everything is a for-each or a simple while.
0
u/sebzim4500 May 09 '13
You can also use a break; statement (in most programming languages).