Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 131,477 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,836 people online right now. Registration is fast and FREE... Join Now!




nested loops

 
Reply to this topicStart new topic

nested loops

area
post 11 Dec, 2005 - 05:20 PM
Post #1


New D.I.C Head

*
Joined: 22 Nov, 2005
Posts: 22


My Contributions


i pretty much understand everything i have learned in my programming class expect these damn nested loops.
my teacher gave me example like this:
for(v=8;v>0;v=v-2)
for(w=1;w<4;w++)
cout<<"v"<<" "<<w;

he wanted us to tell him how many times it will go through the loop and what the values will be? i sat there like a deer in headlights lol. anyhow this is for my own knowledge to know, not for homework or a test. i just want to know how it works.
thanks
User is offlineProfile CardPM

Go to the top of the page


Amadeus
post 11 Dec, 2005 - 06:06 PM
Post #2


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,158



Thanked 31 times

Dream Kudos: 25
My Contributions


For each iteration of the outer loop, the inner loop will be executed 3 times, as w begins at 1, and ends at less than 4. the outer loop, because it starts at 8, ends at greater than 0, and decrements by two, will be executed 4 times. The easiest way to figure them out is to walk through them, and do the math each time.
User is offlineProfile CardPM

Go to the top of the page

area
post 11 Dec, 2005 - 06:21 PM
Post #3


New D.I.C Head

*
Joined: 22 Nov, 2005
Posts: 22


My Contributions


alright thanks cool.gif
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/19/08 11:47PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month