One main difference is
for loop syntax:
for(var i=0; i<10; i++){
//block of executable statements
}
while loop syntax:
var i=0;
while(i<10){
//block of executable statements
i++ //This is optional
}
while loops are best suited when you do not know ahead of time the number of iterations that you need to do. When you know this before entering the loop you can use for loop.for loop syntax:
for(var i=0; i<10; i++){
//block of executable statements
}
while loop syntax:
var i=0;
while(i<10){
//block of executable statements
i++ //This is optional
}
0 comments:
Post a Comment