Frantz Romain
Frantz Romain

Reputation: 846

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.

Upvotes: 1

Views: 319

Answers (3)

Ken White
Ken White

Reputation: 125767

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;
}

Upvotes: 3

prashant
prashant

Reputation: 3608

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.

Upvotes: 0

bmargulies
bmargulies

Reputation: 100196

 while (SOME_CONDITION) {
   /* Block Of Code */
 }

Translates to:

 label:
    if (SOME_CONDITION) {
       /* Block Of Code */
       goto label;
    }

What else is there to know?

Upvotes: 1

Related Questions