what is difrnce btw for and while loop?how they work?
A while loop is a lot like an IF statement. but instead of evaluating the value of a statement once like an IF statement, a while loop evaluates it many times until the loop condition is met. For loops are really very similar. The way I have differentiated them has been to think about for loops over more defined ranges: for x in range (0,100, 2): Print X Whereas the while loop would be similar but would look for a condition to exit the loop: x = 0 while (x > 100): Print (x) x += 2 I hope this helps.
One key difference is that the for loop goes some set number of times and this must be determined before entering the loop. A while loop has no predetermined end. Just a test. So you could do something like `while (RUNNING==true)` and have `RUNNING=true` be right before this. Then, if the user presses q, do `RUNNING=false` Then this would run until the user pressed q to quit.
for gives u a two side range let is starts from here takes a step of this one size and end here whereas while just take some condition that where to end
thankyou for your help.
Join our real-time social learning platform and learn together with your friends!