int i=0;
A1:
cout << “I is “ << i << endl;
i = i + 1;
if ( i <= 10) goto A1;
cout << “the loop is completed\n”;
It is poorly written using goto statements; your job is to convert it into
a. while-loop,
b. do-while loop,
c. for-loop.
int i=0;
A1:
cout << “I is “ << i << endl;
i = i + 1;
if ( i <= 10) goto A1;
cout << “the loop is completed\n”;
It is poorly written using goto statements; your job is to convert it into
a. while-loop,
b. do-while loop,
c. for-loop.
Here is how to fix your problem:
1) Go to http://www.cplusplus.com/doc/tutorial/
2) Learn C++
3) Do it yourself
#include <iostream>
using namespace std;
int main()
{
for (int i=0;i<=10;i++)
{
cout << "I is " << i << endl;
}
cout << "The loop is completed\n";
return 0;
}
This is the for loop.
#include <iostream>
using namespace std;
int main()
{
int i=0;
do
{
cout << "I is " << i << endl;
i++;
}
while(i<=10);
cout << "The loop is completed\n";
return 0;
}
This is the do-while loop.
#include <iostream>
using namespace std;
int main()
{
int i=0;
while (i<=10)
{
cout << "I is " << i << endl;
i++;
}
cout << "The loop is completed\n";
return 0;
}
And this is the while loop.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.