0
Hi... I'm still a beginner, but I want to ask what are the differences between the "for" statment and the "while" statement.
3 Respostas
+ 11
for(initialization; condition; inc/dec){
//statements
}
Note: Best when we know the no of times a loop will run
while(condition){
//statements
}
Used where we don't know how many times a loop will run
+ 9
"For" executes an iteration loop - it iterates through a range, a string, a list/array or any other collection type. It starts at the iterator's first element and finishes at the last (unless told otherwise inside the loop).
"While" executes a conditional loop - it executes *only* or *as long as* its condition is true/True. Some languages also have a do...while loop which executes the code first (so it is sure to fire up at least once) and checks for the validity of the argument at the end.
0
thanks for helping