+ 1
Who does while loop works
I didnot understand while loop
5 Réponses
+ 1
You should really write your question in an understandable way. Without grammar or spelling errors cause like this it's hard to guess want your question is.
+ 1
"How" does while loop work?
while condition:
action
action
optional action to set condition False
It repeats the indented block until the condition is False (or...'while' the condition is True). It can be a compound condition with more than one test, or even an inverted test:
finished = False
while !finished: #( not False .... = True)
stuff
more stuff
if no_more_data:
finished = True
+ 1
repeats an action until a set condition is met
0
I dont know php but while loops are the same in any language.
while(condition){
Statements;
}
So for instance
while(a<b){
//do something;
a++;
}
So as long a is smaller than b the code will loop in the while loop. With a++ I increase the value of a by 1 for each loop. Once a is not smaller than b anymore the code outsidide the while loop will be executed. If you write a loop which you will never escape you have an endless loop which will cause your application to crash.
So in an easy sentance: The while loop will execute until your condition is false.
0
when the condition is true