+ 1

What does the "while" do?

Sorry,I'm beginner.

3rd Jan 2018, 11:22 PM
Luisito Marlo Tolentino
Luisito Marlo Tolentino - avatar
3 Answers
+ 3
while is a form of loop. it will run until told not too. example... run=True while run: print("Hello World") That would result in Hello World being written over and over and over forever because run is always True. count=0 while count<4: print("Hello World") count+=1 that would print Hello World 4 times. each time the loop ran it would print the words and then add 1 to count. "While" count is less than 4 it will continue to loop
3rd Jan 2018, 11:30 PM
LordHill
LordHill - avatar
+ 3
it will run the code inside his curly brackets until the condition is false. Obviously, you need to change that condition every time the code runs, otherwise it will run infinitely. int i; while (i<5) { i++ } increments variable i until it reaches 5, which is false and so it stops at 4
4th Jan 2018, 12:08 AM
Luca Marseglia
Luca Marseglia - avatar
0
ohh,thanks you all😇
4th Jan 2018, 2:18 PM
Luisito Marlo Tolentino
Luisito Marlo Tolentino - avatar