Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
Is it okay if I use a lot of while(true) loops?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
Reply to thread
Message
[QUOTE="Alf P. Steinbach /Usenet, post: 4119870"] * Öö Tiib, on 22.08.2010 04:09: "Exit" is a special command because it needs handling at the level that calls 'doCommand'. That level has to stop looping. In your code you're thinking about 'doCommand' perhaps asking the user to confirm, but you stop looping anyway... So, you can either special-case the signature of 'doCommand' to support "Exit", or you can just handle it directly. Special-casing is problematic because there can be two or three such special cases. It's the KISS principle, Keep It Simple. You might alternatively consider the weaker example double sum = 0.0; cout << explanation << endl; for( ;; ) { double const number = numberFromUser( "Number? " ); if( number == 0.0 ) { break; } sum += number; } But in a way it accentuates the issue because here it's a least plausible to put both the input operation and checking as a 'while' loop condition. To my eyes the 'while', with side-effect condition, obfuscates what the effect of the code is, sort of compiling it down to a lower level language, needlessly extends the scope of a variable, and makes it more difficult to introduce changes, i.e. reduced maintainability. Cheers & hth., - Alf [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
Is it okay if I use a lot of while(true) loops?
Top