简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM