While Loops in C++
learning C++ in my computer science class in school. Im having a hard time picking up the while Looping concept(event controlled, count controlled, Etc). can any one point me in the right decision or send me some great internet sources that explain it way开发者_运维百科 better than the book we are using in class thanks.
While's aren't difficult to understand. Think about it in terms of food:
while (french_fry_count > 0) {
eat_french_fry();
--french_fry_count;
}
while (SOME_CONDITION) {
/* Block Of Code */
}
Translates to:
label:
if (SOME_CONDITION) {
/* Block Of Code */
goto label;
}
What else is there to know?
When i started learning these concepts, i translated it to simple english. For example, in case of while loops, the common english translation could be, do some steps (step 1 , 2 & 3 ) while the "condition" is true. Now the condition can be .. when count of a variable reached to 10, which basically mean you have a while loop based on counting of a variable value. The other scenario where "condition" can change is , 'while you are performing step 1, 2 or 3.. something changed inside while loop which resulted in "condition=false". This is now event based.
精彩评论