OOP CPP Programming language by Nadir Nadeem: Part-3

OOP CPP Programming language by Nadir Nadeem: Part-3

 

 

Table of Contents

C/CPP-Language Loops. 1

Loop: 1

Loop statements: 1

1:- for loop. 1

Infinite loop. 3

Keyword related with loop. 4

2:- while() loop. 5

3:- do-while: 7

 

 

Loop:

  • Repetition is called loop

Loop statements:

  • for()
  • while()
  • do-while

Loop requirement:

  • Starting position(sp)
  • Ending position (Condition)(ep)
  • Jump (inc/dec)

1:- for loop

Syntax:

  • For(sp; ep; inc/dec){
    • Loop body
  • }

Example:

Example:

Example: more than one increment (+=)

Ass#23 write number in brackets

(1):- Pakistan

(2):- Pakistan

Ass#24: standard table

Enter table value:= 3

1 * 3 = 3

2 * 3 = 6

3*3=9

10*3= 30

Ass#25: table with input end value

Enter table value:= 3

Enter end value:= 3

1 * 3 = 3

2*3=6

3*3=9

Ass#25: table with input end not more than 25

Enter table value:= 3

Enter end value:= 3

1 * 3 = 3

2*3=6

3*3=9

Ass#26: print text to required number

Enter your text:= Ali

How many value you want to write it:= 100

Ass#27: draw rectangle with *

************************************

*                                               *

*                                               *

************************************

Infinite loop

Syntax:

  • for(;;){
    • Loop body
  • }

Example:

Example: infinite loop with condition

Keyword related with loop

  • break
  • continue

example:

2:- while() loop

Syntax:

Sp;

while(ep){

               loop body

               inc/dec

}

Example:

While() infinite

Syntax:

While(True){

               Loop body

}

Example:

Example:

3:- do-while:

Syntax:

do{

               loop body

               inc/dec

} while(ep);

Example:

23,24,25,26,27 with while and do while

Last assè 36