how to use for statement?

I understand it's used in loops, but how exactly?

Can you give me example on how to use it, like:

1
2
3
4
cout << "asks user to input a number";
cin >> number;
if (number == 0) { "loop above part"
}


That is just example how i'd want things to go, ask a question and the answer cannot be 0, otherwise it asks again and again until 'number != 0'

EDIT: i'm just a newbie so far, just to inform.
Last edited on
for is usually used to repeat a block a certain amount of times, for other types of loop a while or do-while may be better

Here is a tutorial on the for loop: http://www.cplusplus.com/doc/tutorial/control.html#for
I just took a look at that and noticed goto statement and gave it a shot and it worked :)

I probably didn't get to 'goto' in tutorial im following, so thanks :)
Now you have to tell me whats wrong with goto? :(
it works fine.... :D
It's just less structured, makes the code more complicated to read. I admit, I've used gotos before. Normally for when I have nested loops and I need to break from all the loops and I'm too lazy to make another variable to be checked for and allow multiple breaks.
If you plan on getting a job, forget about goto. Goto makes debugging a massive pain in the a**.
The only good thing of goto is that you never really need it
Topic archived. No new replies allowed.