By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,513 Members | 1,650 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,513 IT Pros & Developers. It's quick & easy.

FOR LOOP

P: n/a
I have some trouble understanding the for loop. Can any one explain the
basic structure and functionality of a for loop to me?

Oct 22 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a

"coinjo" <co****@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
I have some trouble understanding the for loop. Can any one explain the
basic structure and functionality of a for loop to me?


for(init; condition; iteration)
{
/* body */
}

X:

1. expression 'init' is evaluated

2. expression 'condition' is evaluated; if
it evaluates to false, execution flow
continues at X: ; if it evaluates to true,
statements within 'body' are executed; then ...

3. expression 'iteration' is evaluated

4. Go to 2.

Note: Each of 'init', 'condition', and 'iteration',
are optional (but the semicolons are not).

Example:

for(int i = 0; i < 10; ++i)
{
foo();
}

Function foo() will be called exactly ten times, then
execution flow continues after the closing brace ( } )

Which C++ book(s) are you reading that don't explain
this very basic programming element?

-Mike
Oct 22 '05 #2

P: n/a
Thanks for you generous help. I was thinking that instead of
understanding it from a book i should ask a person. In this way i can
understand things better and more quickly.

Oct 22 '05 #3

P: n/a
"coinjo" <co****@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com
Thanks for you generous help. I was thinking that instead of
understanding it from a book i should ask a person. In this way i can
understand things better and more quickly.


Do you think that books are not written by people? Whether it is an
explanation here or in a book, it is just typed words in either case.

--
John Carson

Oct 22 '05 #4

P: n/a

"coinjo" <co****@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Thanks for you generous help. I was thinking that instead of
understanding it from a book i should ask a person. In this way i can
understand things better and more quickly.


I must respectfully disagree. I don't think you
can learn C++ without at least one book (more than
one would be better). Also note that it will take
time (at least several months, possibly years,
depending upon how much time you have to devote
to it).

You can get guidance in choosing books by reading
the peer reviews at www.accu.org

-Mike
Oct 22 '05 #5

P: n/a
if you don't know the for loop but probably have no idea about debugging
and declarations etc. This can be very frustrating at the beginning so i
suggest for you to book a beginner course. After you have something to
sit on when you start to scuffle your hairs about progs..:-)
Also you might take in consideration VB.NET ...
Oct 22 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.