+ 1
Is this while condition is valid?? :-
#include<iostream> using namespace std; int main() {int a; while(a<7) {} return 0; }
5 ответов
+ 7
Not valid. a does not have any value.
#include<iostream>
using namespace std;
int main()
{int a=5; //initializing a
while(a<7)
{}
return 0;
}
//Now the code would run in an infinite loop
#include<iostream>
using namespace std;
int main()
{int a=5;
while(a<7)
{a++;}
return 0;
}
//Now the code would run but give no output
#include<iostream>
using namespace std;
int main()
{int a=5;
while(a<7)
{a++;
cout <<a;}
return 0;
}
//Now codes runs and prints 67
+ 2
it is not returning anything.
+ 2
it is valid condition, but because there is nothing in the while block you get an infinite loop.
-try increasing a in the while loop
-also print something so that you see some output
eg:
cout<<a++;
[edit]
also 'a' needs bring initialized otherwise will be a random number, maybe greater than 7.
+ 1
the condition is valid buy it is nonsense because a is not initialised and count of loops is not defined.The curly brackets are wasted on other hand the semicolon is missing and there is no defined incresing statement.