c++ - Which example for a do-while loop? -


inside of do-while loop , if else statements in best interest @ end of statements change variables value , use create while boolean expression, or best set while expression being true, , use break statement in if else statements.

to clarify, here 2 methods.

do { cout << "what choice?" << endl; cin >> choice;   if(choice == 1)   {     cout << "you chose 1" << endl;     dowhilemodifier = 1;   } else {     cout << "that's not correct choice" << endl;     dowhilemodifier = 0;   } } while (dowhilemodifier == 0); 

vs

do { cout << "what choice?" << endl; cin >> choice;   if(choice == 1)   {     cout << "you chose 1" << endl;     break;   } else {     cout << "that's not correct choice" << endl;   } } while (true); 

i did first way, i'm leaning towards second example.

input appreciated!

both do-while loops job done personal preference on do-while loop want have in code. if second 1 better suggest doing while loop , not do-while loop since simpler, easier read, , same thing do-while loop anyways.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -