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.

Recommended Answers

All 2 Replies

#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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.