0

is while loop without condition possible while () { //body }

18th Jan 2017, 8:22 AM
aswathy
aswathy - avatar
4 Respostas
+ 2
Nope, it must have a valid boolean expression inside the (parentheses). If you want it to be an infinite loop, it should be "while(true) {...}".
18th Jan 2017, 8:39 AM
Álvaro
+ 2
Yes, @aswathy, even if you have an infinite loop, like in "while(true){...}" you can (well, you *should*) have a break statement inside the while body. For example, while(true) { cin >> x; if (x < 0) { break; } else { cout << "The double of x is " << x << endl; } } ...will keep printing the double of the numbers you enter, provided they're positive or 0. If you enter a negative number, this acts as a "signal", and the loop finishes.
18th Jan 2017, 5:47 PM
Álvaro
+ 1
Yes , But U cannot stop it as it runs for infinite times . so there must be a condition , atleast Boolean Expression
18th Jan 2017, 9:11 AM
SUMANTH VENKATA SAI KRISHNA Manduru
SUMANTH VENKATA SAI KRISHNA Manduru - avatar
+ 1
the condition can be in the body of while loop eg break statement? ??
18th Jan 2017, 11:41 AM
aswathy
aswathy - avatar