Nested+Loops

# Nested+Loops - cout<<" y="<< y<< endl y...

This preview shows pages 1–2. Sign up to view the full content.

Nested Loops n Loops can be contained “inside” the body of  another loop. n These are called  nested loops . int x = 0, y = 0, z = 0; while (x < 10) { while (y < 20) { y++; z++; } x++; Outer Loop Inner Loop z  will be equal to 200 after the loops finish executing

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Nested Loops:  Example int x = 0, y = 0, z = 0; // Outer Loop while (x < 2) { cout << "Outer Loop: x=” << x;
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: cout << ", y=" << y << endl; y = 0; // Inner Loop while (y < 3) { cout << "Inner Loop: x=" << x; cout << ", y=" << y << endl; y++; Screen Output: Outer Loop: x=0, y=0 Inner Loop: x=0, y=0 Inner Loop: x=0, y=1 Inner Loop: x=0, y=2 Outer Loop: x=1, y=3 Inner Loop: x=1, y=0 Inner Loop: x=1, y=1 Inner Loop: x=1, y=2 Why is y=3 here?...
View Full Document

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern