n00b question: for loops

Status
Not open for further replies.

NX5

Solid State Member
Messages
20
Hi

This question must have been asked by every single newbie everywhere! I really don't get for loops. I'm talking about in JavaScript here. Can anyone explain it to me in simple language?

Thanks
 
A loop is a function or whatever you would like to call it

It will repeat itself until until the condition is met or it is exited

example : a loop could be from 1 to 10. It will print out, or do whatever function you tell it to do untill it reaches 10. Then it exits the loop

start loop
1: test
2: test
3: test
4: test
5: test
6: test
7: test
8: test
9: test
10: test
exit loop(the condition had been met..has arrived at 10)

There is many different kinds of loops but they mainly function in the same way.
 
take this for example

int i;
for (i=0; i<15; i++)
{
system.out.println(i);
system.out.println();
}
this would print out
0
1
2
...
15
the i= is wat i starts at. The i< is wat it finishes, and I++ mean it add 1 each time.
and itl repeat the loop till it reaches the number that is befor <
 
that would actually only go until 14. to print out the 15 it would have to be for (i=0;i<=15;i++)
 
Status
Not open for further replies.
Back
Top Bottom