NESTED LOOPS IN C++ LANGUAGE, Slides of C programming

THESE SLIDES ARE FOR BEGINNERS WHO ARE EAGER TO LEARN PROGAMMING LANGUAGES FROM SCRATCH...THESE SLIDES CONTAIN SOME BASIC INFO...

Typology: Slides

2021/2022

Available from 08/21/2022

SamenKhan
SamenKhan 🇵🇰

231 documents

1 / 12

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
.
Nested loops
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download NESTED LOOPS IN C++ LANGUAGE and more Slides C programming in PDF only on Docsity!

.

Nested loops

Nested Loops

  • A loop can be nested inside of another loop.
  • C++ allows at least 256 levels of nesting
  • When working with nested loops, the outer loop changes only after the inner loop is completely finished

The syntax for a nested while

loop statement in C++

while(condition) { while(condition) { statement(s); } statement(s); // you can put more statements. }

The syntax for a nested

do...while loop statement in C++

do { statement(s); // you can put more statements. do { statement(s); } while( condition ); } while( condition );

7 *Nested loops (loop in loop) cin >> a >> b; for (int i = 0; i < a; i++) { for (int j=0; j<b; j++) { cout << “”; } cout << endl; }





b a

8 *Nested loops (2) int a,b; cin >> a >> b; for (int i = 0; i < a; i++) { for (int j=0; j<b; j++) { if (j > i) break; cout << “”; } cout << endl; }

**



b a

Assignment

❑Due next Class ❑Send all your assignments to the CR and he will forward them to be prior to the class. ❑Only electronic versions will be accepted ❑Copied Assignments will be marked zero ❑Late Assignment not accepted ❑Don’t forget to write your name ❑Also, include a screenshot of the output (^10)

11 **Nested loops






Draw a flowchart, write the pseudo code and write a program that displays the following output