0
is while loop without condition possible while () { //body }
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) {...}".
+ 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.
+ 1
Yes , But U cannot stop it as it runs for infinite times .
so there must be a condition , atleast Boolean Expression
+ 1
the condition can be in the body of while loop eg break statement? ??