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

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

View Full Document Right Arrow Icon
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++; } Outer Loop Inner Loop z  will be equal to 200 after the loops finish executing
Background image of page 1

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

View Full DocumentRight Arrow Icon
Nested Loops:  Example int x = 0, y = 0, z = 0; // Outer Loop while (x < 2) { cout << "Outer Loop: x=” << x;
Background image of page 2
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

This note was uploaded on 02/14/2012 for the course ENGR 101 taught by Professor Ringenberg during the Fall '07 term at University of Michigan.

Page1 / 2

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

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online