This is the problem im working on:

*Write a program that has nested loops
*First, write the inner loop
-Use “for” loop to display Hello two times
*Second, write the outer loop
-Use “do while” loop to display the inner loop three times
-Before the output of inner loop, you should display a statement that says:
"Iteration 1 from outer loop" (the number 1 will change according to the iteration. What should you use?)

I am usure of how to nest a "for" loop and a "do while" loop. i am not even sure exactly what the problem is asking when it says use the "do while" loop to display the inner loop three times. can someone please help me out? this is all i have so far:

#include<iostream>
using namespace std;

int main()
{
	int outer_loop, inner_loop;
	for(inner_loop=1; inner_loop<=2; inner_loop=inner_loop+1)
	{
		cout<<"Hello"<<"\n";
	}

	return 0;
}

Recommended Answers

All 5 Replies

Nest loops by putting one inside the other:

while (xxx)
{
    for (x;y;z)
    {
        do
        {
        } while (aaa);

    }
}

Nest loops by putting one inside the other:

while (xxx)
{
    for (x;y;z)
    {
        do
        {
        } while (aaa);

    }
}

ok thanks that helps but can you be a little more specific cause i am still having trouble figuring out what to put where. what does it mean display the inner loop 3 times? is it asking to display the text "inner loop" or what, im confused.

Which one is the inner loop? Which one is the outer loop?

ok ive figured everything out except this part:

Before the output of inner loop, you should display a statement that says:
"Iteration 1 from outer loop" (the number 1 will change according to the iteration. What should you use?)

Oh come on, really. What should you use to output a statement? You can't be that new. Didn't you do a Hello World program?

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.