Click to See Complete Forum and Search --> : whats the dif?


Da Warriah
12-08-2002, 07:40 AM
whats the difference between a for loop and a while loop? i mean, i know that for is if you know the variable and while is if you dont or something, but could anyone explain that to me, and maybe give me an example or two? cause im totally lost....

sciguyryan
08-09-2003, 08:01 AM
hi,


there is no difference at all they are only used differently depending on the situation. one is more suted to one situation than the other that is the only difference.

AdamGundry
08-09-2003, 10:58 AM
See the documentation:
for loop (http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/stmt.html#1004804
)
while loop (http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/stmt.html#1004896)

Basically, for loops should be used when you need to iterate a known number of times, and while loops when you need to loop until something happens. For example:

for (i=1;i<=5;i++){
document.write(i + ','); // Prints 1,2,3,4,5,
}

aVar = true;
while (aVar){
aVar = doSomething(); // Keeps calling doSomething() until it returns false.
}

Adam

sciguyryan
08-10-2003, 05:30 AM
hi,


so, there is a difference for the different kinds of loop.

pelegk1
08-10-2003, 06:00 AM
its in there way of use usually
and not the defenition itself that means " going over something......"

Israel is the bes way the live in
Gaza is the most **** place to live in