help with while and for.
-
can you make me an example with while and for, thank you,please describe everything im a beginner. thanks. bye khodadad@eminem.com
-
can you make me an example with while and for, thank you,please describe everything im a beginner. thanks. bye khodadad@eminem.com
for(int nLoop = 0; nLoop < 10; nLoop++)
{
// Do something ten times
}int x = 0;
while(x < 10)
{
x++;
}If you are a beginner, I suggest you need a few books to learn the basics of C++. Michael 'War is at best barbarism...Its glory is all moonshine. It is only those who have neither fired a shot nor heard the shrieks and groans of the wounded who cry aloud for blood, more vengeance, more desolation. War is hell.' - General William Sherman, 1879
-
for(int nLoop = 0; nLoop < 10; nLoop++)
{
// Do something ten times
}int x = 0;
while(x < 10)
{
x++;
}If you are a beginner, I suggest you need a few books to learn the basics of C++. Michael 'War is at best barbarism...Its glory is all moonshine. It is only those who have neither fired a shot nor heard the shrieks and groans of the wounded who cry aloud for blood, more vengeance, more desolation. War is hell.' - General William Sherman, 1879
Michael P Butler wrote: If you are a beginner, I suggest you need a few books to learn the basics of C++. ..and the fact that this question was answered already, yesterday suggest, that he's not taking any of our advice! http://www.codeproject.com/script/comments/forums.asp?forumid=1647&select=613572&df=100&exp=0&fr=126#xx613572xx[^] Get a book, read the suggested website; their are a lot of free websites thats willing to teach you c++ from the ground up, including
for
andwhile
loops (do a google search). **I Dream of Absolute Zero
**
-
can you make me an example with while and for, thank you,please describe everything im a beginner. thanks. bye khodadad@eminem.com
Don't mind me, I'm in a teaching mood! There are three diffrent looping structures within The C Programming Language and C++ (an extension of C). There are:
- for
- while
- do-while
Here is a brief description for each:
- for: The for loop is mainly used to step through something, like an array. It syntax is "for( staring index ; condition ; increment ) Statement" These statements can be incremented (or decremented) by a known value, like 1, 3, 5, 56, ... You don't need all the items within the paranthesis, but you do need the semi-colons. Example:
= x;
for( ;; )...
Here I have an endless loop.
for( ; x < 10; ) ...
Here it is like the while loop. - while The while loop is used to do looping until a condition is met. One example for the while would be in polling something. You continue waiting until the event occurs then drop out of the loop. You can interchange the for/while exactly like one of the post stated. The condition testing is done at the beginning of the loop.
- do-while This loop structure is a different animal than the rest. Unlike the for/while loops where they must first pass the condition to execute, the do-while will always execute the loop once. The condition testing is done at the end of the loop instead of the beginning.
I hope this helps. The uses that I described are not hard and fast, but they can be used as a guide line if your new until you get more experience. Larry J. Siddens Cornerstone Communications TAME THE DOCUMENT MONSTER www.unifier.biz
-
can you make me an example with while and for, thank you,please describe everything im a beginner. thanks. bye khodadad@eminem.com
Hi there Example, new to this myself!! :-D { //Create vector put 26 numbers into it //using for loop for(int i = 0; i < 26; ++i) { Vec.push_back(i * 2); // pushback * 2 //2,4,6,8,10...... cout << Vec.at(i) << "\n"; //Display } Not that dificult hey. Regards bhangie:-D