Hello, I am new to programming. Please help me with what is wrong with my code.
#include <iostream>
using namespace std;
int main() {
int x;
//while(cin>>x)
while(true)
{
cin>>x;
if(x!=42)
cout<<x<<endl;
else
break;
}
return 0;
}
I am getting the message time limit exceeded. But the following code is work.
#include <iostream>
using namespace std;
int main() {
int x;
while(cin>>x)
//while(true)
{
//cin>>x;
if(x!=42)
cout<<x<<endl;
else
break;
}
return 0;
}
What is the difference in using while(1) and while(cin>>x)?
Thanks in advance!