Can someone explain a for loop to me?

closed account (4wRjE3v7)
for (i=1,i<=num;i++)


-thank you
Indicate? what do you mean by indicate? By indicate do you mean what value does i hold? That would be 1 assuming i has been declared as an int.

What does the loop mean? That would depend on the context, from what is given and assuming that i is an int, it would mean do the loop body for a total number of iterations of 1 to num times.

The code you have given is very broad as we cannot see 1) what data type i is, 2) what data type/value num is 3) what the loop body is.
i think he meant this,,,

x++ increments the value of variable x after processing the current statement.
++x increments the value of variable x before processing the current statement.

So just decide on the logic you write.

x += ++i will increment i and add i+1 to x.
x += i++ will add i to x, then increment i.

by BeowulfOF
Last edited on
closed account (4wRjE3v7)
I want to know what the i is, what it does, everything!!! thanks

for ( init-expression ; cond-expression ; loop-expression ) 

for (int i=1;i<=num;++i)

read this
Last edited on
for (i=1,i<=num;i++)

This doesn't work. A for-loop looks like this:
for (initialize counter variable; condition; statement after each loop) {
    some statements

This would rather fit in the Beginner section. And why don't you just google it anyway? It would take 15 seconds at most.
Topic archived. No new replies allowed.