+ 1
I'm confused how the "while" statement works.
I'm just don't understand how while works. Can someone explain it to me?
7 Answers
+ 11
syntax:
while <condition>:
<statement>
<statement>
...
<after while loop>
explanation:
1. the condition is evaluated;
2. if the condition is true, execute the statements; if it is false jump to what comes after the while loop
3. start over from step 1.
+ 1
Suppose you want to draw the black balls from a Box having 10 balls.
noOfBalls = 10
while(noOfBalls not equal to 0):
#keep on drawing the balls
noOfBalls-=1
So you need to keep on drawing the balls till the box becomes empty.
so if you take a condition after writing while, then the loop within that while statement will keep on getting executed till the condition is satisfied.
0
until condition is true, while loop is executes
while (i>10) now the statements in while are executes until the valid of i is greater than 10
0
Sorry, I'm only a third grader. Can you use a bit easier words? Thanks for answering though!!
0
Thank you.
0
while there is a cookie in the cookie jar take a cookie out of the cookie jar. If there are 0 cookies in the cookie jar then buy cookies. The English example.
0
Ok. Thanks