In C++, use the While statement for the outer loop and the for statement for the
ID: 3634121 • Letter: I
Question
In C++, use the While statement for the outer loop and the for statement for the nested loop.
Then rewrite to use Do / While statement for the outer loop
This is what I have, but needs to be checked by an expert.
//While statement outer loop and For nested loop
#include
using namespace std;
int main()
{
int nested 1;
while (int outer = 1; outer <= 2; outer +=1;)
{
do //begin loop
{
cout << nested;
cin >> " ";
nested += 1;
} for (nested < 4);
cout << endl;
nested = 1;
} //end for
<code>
<code>
//Do/While statement outer loop
#include
using namespace std;
int main()
{
int nested 1;
for (int outer = 1; outer <= 2; outer +=1;)
{
do //begin loop
{
cout << nested;
cin >> " ";
nested += 1;
} while (nested < 4);
cout << endl;
nested = 1;
} //end for
<code>
Thanks
Explanation / Answer
please rate - thanks
had to guess at what it was doing
#include <iostream>
using namespace std;
int main()
{
int nested=1;
int outer=1;
while (outer <= 2)
{
for(nested=1;nested<4;nested++)
{
cout <<"nested = "<< nested<<" outer="<<outer<<endl;
}
outer +=1;
} //end for
cout<<" second set of lopops ";
//Do/While statement outer loop
outer=1;
do
{
for(nested=1;nested<4;nested++)
{
cout <<"nested = "<< nested<<" outer="<<outer<<endl;
}
outer +=1;
} while (outer <= 2);
system("pause");
return 0;
}