
-----------------------------------
HazySmoke)345
Wed Mar 15, 2006 12:53 pm

How to do loop statements in C++?
-----------------------------------
How to do loop statements in C++?

Either I'm really blind, or I just can't find it in the tutorial index. In VB, there are these three types of loop statements... While, Do, and For. I wonder if there are similar structures in C++...

-----------------------------------
wtd
Wed Mar 15, 2006 1:03 pm


-----------------------------------
http://merd.sourceforge.net/pixel/language-study/syntax-across-languages/CntrFlow.html#CntrFlowLoop

-----------------------------------
Justin_
Wed Mar 15, 2006 1:55 pm


-----------------------------------
Here's a link that will actually help you.  I think wtd missed the part where you said you wanted to know how to do them. http://cplus.about.com/od/beginnerctutorial/l/aa031602a.htm

-----------------------------------
Justin_
Wed Mar 15, 2006 2:03 pm


-----------------------------------
By the way, all I did was type: "c++ loops" in a google search field to come up with that link.  Next time try searching for an answer before asking.

-----------------------------------
wtd
Wed Mar 15, 2006 2:08 pm


-----------------------------------
If it's not possible to figure it out from the information provided by the site I linked to, then one would need a better grasp of more fundamental concepts anyway.

Keep in mind that when I post I assume people will learn by mastering simple concepts and building on them.  This is the standard I hold people to.  If declaration and initialization or expressions need to be explained, then I can only conclude that the student in question is not ready to learn about loops.

-----------------------------------
Justin_
Wed Mar 15, 2006 3:31 pm


-----------------------------------
wtd honestly, you're link had a bunch of dissembodied information mostly not even pertaining to c++.  It was ugly and had no explaination and poor examples.  

The only thing I can say to you is "keep your audience in mind".  I don't expect you to concede since you never do so what do you say we allow HazySmoke to say which link he found more useful?

-----------------------------------
wtd
Wed Mar 15, 2006 4:00 pm


-----------------------------------
The comparative usefulness of things is often only apparent to us long after the fact.  :)

-----------------------------------
Justin_
Wed Mar 15, 2006 4:09 pm


-----------------------------------
lol, so true.  But, you're just saying that cause you know he'll side with me.

-----------------------------------
wtd
Wed Mar 15, 2006 4:23 pm


-----------------------------------
I'm saying it because we have lots of people here ask questions like this and providing an easy answer often seems like the most useful thing, but it often does them a disservice.

-----------------------------------
Justin_
Wed Mar 15, 2006 4:44 pm


-----------------------------------
You're going to call me a troll or some wierd thing for saying this, but remember when you told me java passes objects by reference?  Isn't that like an easy answer?  

So give me the easy answer, give him the wacked out complicated one?

-----------------------------------
MysticVegeta
Sat Mar 18, 2006 5:57 pm


-----------------------------------
I thought wtd's link was pretty good because it had a comparison between many languages loops (including VB which the person is used to program in) So I guess it was fairly easy for him to compare the loop structures.

-----------------------------------
El Cid
Sun Apr 30, 2006 10:07 pm


-----------------------------------
Let me summarize the information here.

for loop: usually used when you know how many times you want to run the loop before you start; printing repeated characters comes to mind.
Example:

for(int i=9; i > 0; i--)
cout 0. As long as that's true, cout '*' and decrement i by 1 at the end of the loop; check to see if i > 0 is still true, etc...; exits loop when i>0 becomes false.


while loop: usually used when you want to stop when a certain conditions is met; very useful for reading from files.

Example:

int num_words = 0;
string word;
cin >> word;

while(word != "end")
{
i++;
cin >> word;
}
cout  accident;
i++;
}
while(accident != "fall");
cout 