for (int i; i>0; i++) WHEN I USE FOR LOOP, SOLUTION GETS REJECTED PLS TELL WHY SHOULD I USE WHILE LOOP ONLY. { int j; ALSO IF I DECLARE VARIABLE INSIDE THE LOOP , SOLUTION GETS REJECTED...WHY?? cin>> j; if(j==42) break; else cout<< j << "\n"; } return 0;
You need to take input.Are you taking input using cin??? I guess no.the code should be: int i; while(1){ cin>>i; if(i==42) break; cout<<i<<endl; }
my bad...though my submission has been accepted.
yes I had used cin .
but my query is different
can you solve this by using "for" loop.
if not then why not?
for ( ; ; ){int i;cin>>i;if (i==42)break;cout <<i <<endl;}
thnx