I'm confused how the "while" statement works. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I'm confused how the "while" statement works.

I'm just don't understand how while works. Can someone explain it to me?

22nd Apr 2017, 4:13 PM
Brian
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.
22nd Apr 2017, 4:23 PM
Ulisses Cruz
Ulisses Cruz - avatar
+ 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.
23rd Apr 2017, 3:31 AM
Tamoghna Saha
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
22nd Apr 2017, 4:22 PM
Mayur Chaudhari
Mayur Chaudhari - avatar
0
Sorry, I'm only a third grader. Can you use a bit easier words? Thanks for answering though!!
22nd Apr 2017, 5:29 PM
Brian
0
Thank you.
23rd Apr 2017, 6:28 PM
Brian
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.
24th Apr 2017, 10:29 AM
James
James - avatar
0
Ok. Thanks
24th Apr 2017, 11:29 PM
Brian