inquiry about while loop
May 19, 2013 at 5:12pm
why does the programe output the last two numbers
5 1 respectively ??
they should be
????
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
#include<iostream>
using namespace std;
int main()
{
int i=1;int j=1; int n=5;
while(i<n)
{
int j=3;
cout<<i<< " " <<j<< " ";
++i;
++j;
}
cout<<i<< " "<<j<<" ";
return 0;
}
| |
May 19, 2013 at 5:16pm
The loop will keep running as long as i < n. When i becomes 5, i < n becomes false, and the loop stops.
May 19, 2013 at 5:23pm
when the loop stops ,, the program execute the next statement after the loop??
May 19, 2013 at 6:12pm
Yes, when the loop ends it will run the code that is after the loop.
May 19, 2013 at 6:12pm
when the loop stops ,, the program execute the next statement after the loop? |
Yes it continues execution from firs statement after body of loop
May 19, 2013 at 7:26pm
thankss guyss
Topic archived. No new replies allowed.