+ 2

Why we can use "while true : " insted of while with an expression?

3rd Sep 2018, 3:18 PM
Hari Krishna Sahu
Hari Krishna Sahu - avatar
4 Respostas
+ 1
I think I understand the question. You are saying, why does "while True:" work instead of "while <expression>"? I believe this question is for Python as well? If so, you can use: while True: while 1==1: x=0 while x < 10: print(x) x += 1 There are more variations, but these are the first that come to mind. You can have expressions with a while loop. Just remember the recommendation from Tim Peters with regards to simplicity. Best of luck.
3rd Sep 2018, 3:23 PM
Steven M
Steven M - avatar
+ 1
When the no. of execution are know by us....we can go for expression.... When we DONT Know the no. of execution we go for infinite loop by using true.... instead of expression
10th Sep 2018, 6:02 PM
Shivadharshini Nagaraju
Shivadharshini Nagaraju - avatar
0
For a while condition, your computer takes anything that can be evaluated as yes or no, something or nothing, 1 or 0. If you write 'while True' , you just give out the 1 directly instead of checking for anything (you could also write 'while 1'). It basically means: while whatever (at least whatever's something ^^) do this and that (or until you say otherwise (namely 'break')).
3rd Sep 2018, 3:26 PM
HonFu
HonFu - avatar
0
the expression is a boolean expression, like 1 == 0, 5 < 6, and true. They are all expressions that result in a boolean value
3rd Sep 2018, 7:25 PM
Dan Walker
Dan Walker - avatar