1. ## Don't understand Loops

Can anyone tell me what exaxtly IS loops? I did learn the tutorial in http://www.cprogramming.com/tutorial/lesson3.html . But i don't seemed to understand what's the function of "endl". I also don't understand why why is endl put in, for example, cout<< x <<endl;. And what is x++, x = x + 10, or even x = random ( 5 ). What do they mean when they says "The variable update section is the easiest way for a for loop to handle changing of the variable"?
I fully understand DO..WHILE loops, and i think I understand a bit of While loops.
But still, can anyone explain what's While loops is? Thanks in advance people =)

2. it is not While. C++ is case sensitive.
Code:
```while (/*condition*/(1!=2 && 2 = (3-1))
{ // starting brace
//code for while loop
} // ending brace```
a while loops is identical to a do while, except to put while at the top of the section, and take out the do.
a for loop is self explanatory.

as for you firsts question.
loops is just a word to suggest the use of a while loop, a for loop, of a do while loop

std::endl is a function that clear the output buffer, and carries your cursor to a new line. ( endl == endline )

3. Code:
`cout << x << endl;`
Send through the standard output stream some representation of x and then a new line.

Code:
`x++;`
Add one unit to x. Return old value.

Code:
`x = x + 10;`
Assign a value to x that is ten more than what x currently is.

Code:
`x = random(5);`
I am not familiar with this, but...
Code:
`x = rand() % 5;`
would be a rough (and usually naive) way to assign a value to x that is between 0 and 4, inclusive.

4. Originally Posted by Raigne
Code:
`while (/*condition*/(1!=2 && 2 = (3-1))`
a for loop is self explanatory.

std::endl is a function that clear the output buffer, and carries your cursor to a new line. ( endl == endline )
I still don't get it. The condition you've given, which is (1!=2 && 2 = (3-1), does what? I know that in the bracket, 1 != 2 means that when 1 is not equal to 2. I also know that in the bracket, && means AND, which states that both value must be true in order to get a true. But i really don't understand what's that 2 = (3-1) thing. Why is that equation doing there and what is it purpose? Oh, and when I look at the tutorial, they had something like x++, and x = rand or something. What are all those???

Oh, and you said that endl is a function that clear the output buffer, and carries your cursor to a new line. ( endl == endline) Do you mean that it is something like cout<<"blah\n". Do you mean that it posses the same function as "\n" in the cout, which also means the next line?

Man, i'm soo noob T.T. Can I really learn C++? It looks really hard and indeed, it's hard to learn. I really want to learn it well. Those examples given in thsoe tutorials arn't enough. Can you guys add me in MSN, so that you guys can teach me please? I am really desparate in learning C++. I want to learn all its C++ function. <<snipped>>

Oh, and by the way, I'm a complete newbie/noob in programming. I have no previous programming knowledge. This is my first time learning how to programme...So please guys, lend a helping hand. I really need help~~

5. Originally Posted by Raigne
it is not While. C++ is case sensitive.
a while loops is identical to a do while, except to put while at the top of the section, and take out the do.
Nonsense. A do-while loop is guarenteed to have its contents executed at least once. A while loop on the other hand can quite happily execute the loop contents zero times, if the condition is initially false. It's all about whether you evaulate the condition beforehand or not.

2 = (3-1) is incorrect because of the missing double-equals (==), and will not compile. It would have to be 2 == (3-1)

6. zomg, still I only understand the while loop and the for loop. I really dun understand for loops>.< Can you guys explain in details and give some working examples, made it so that newbie can understand it well. Oh, and seriously, what's the real function of endl? Is it the same function as "\n" in the cout, like the next line?

7. Originally Posted by ofayto
zomg, still I only understand the while loop and the for loop. I really dun understand for loops>.< Can you guys explain in details and give some working examples, made it so that newbie can understand it well.
Print "Hello world" 100 times:
Code:
```for (int i = 0; i < 100; ++i) {
cout << "Hello world" << endl;
}```
Print "Hello world while user doesn't type "N":
Code:
```char choice = 'Y';
do {
cout << "Hello world" << endl;
cout << "Do again? Y/N ";
cin >> choice;
} while (choice != 'N');```
Oh, and seriously, what's the real function of endl? Is it the same function as "\n" in the cout, like the next line?
endline. Same as "\n", except it flushes the output buffer, forcing immediate write to the screen. Therefore "\n" may be more efficient, as the buffer is written to the screen when it gets full (or some other condition is met - program termination, input statement etc)

You should probably read some tutorials and experiment with code snippets yourself.

8. Originally Posted by CodeMonkey
I am not familiar with this, but...
Code:
`x = rand() % 5;`
would be a rough (and usually naive) way to assign a value to x that is between 0 and 4, inclusive.
Thats how I would generate a random number (0-4) in C/C++. Is there a better way to do this?

9. Originally Posted by ofayto
zomg, still I only understand the while loop and the for loop. I really dun understand for loops>.< Can you guys explain in details and give some working examples, made it so that newbie can understand it well. Oh, and seriously, what's the real function of endl? Is it the same function as "\n" in the cout, like the next line?
A for loop works like this:
Code:
```for (*called when initialized*; *condition to be true*; *called after each loop*)
{
}

//Example:
for (int i = 0; i < 5; i++)
{
cout << i << endl;
}```
On initialization we declare a variable i and set it to zero, then we say that to run the code i should be less than five. And at last we say that after each loop i should be increased by one.
Inside the loop we simply print out the value of i, followed by an endline.

10. Thats how I would generate a random number (0-4) in C/C++. Is there a better way to do this?
Beware of C/C++. But yes, there is a better way. It is because not all of the bits in a value given by std::rand() have a good period. This has been discussed on the board many times.
Read under "Standard Library" here: http://eternallyconfuzzled.com/tuts/..._tut_rand.aspx

*edit* even better, just read this: http://eternallyconfuzzled.com/arts/jsw_art_rand.aspx

11. Cheers. That sort of stuff is good to know

12. So there is someone else having trouble with C++ can anyone do tutoring one on one--need help with the same trouble as above and much more--I'll pay for the help