Presentation is loading. Please wait.

Presentation is loading. Please wait.

 An instruction or group of instructions.  Computer executes program repeatedly for specified number of times. Or until some terminating conditions are.

Similar presentations


Presentation on theme: " An instruction or group of instructions.  Computer executes program repeatedly for specified number of times. Or until some terminating conditions are."— Presentation transcript:

1  An instruction or group of instructions.  Computer executes program repeatedly for specified number of times. Or until some terminating conditions are satisfied. 3

2  There are two types of loop. A. Determinant loop or counter loop: Extremely powerful loop. This loop is used, when the number of executions or iteration is known. Used in programs like print “university of swat” 5 times. Etc. 2

3 B. Undeterminant loop or controlled loop: Its Execution depends upon the condition either true or false. The number of iteration is not known before the operation. While and do while loops are used here. 3

4  There are three methods to loop a program. A.Using For loop or (For statement). B.Using while loop or (while statement). C.Using do while loop or (do while statement). 4

5  The popular and mostly used loop.  It is determinant loop.  It checks the condition before execution. Which means that it is pretest loop. 5

6 A.INITIALIZATION : Means to assign value for variable to initialize the loop. i.e (azr=11). B.CONDITION : Test the condition either it reach the desire number of execution or not. i.e (azr<=20). C.EXPRESSION UPDATE : It increases the loop counter as much it executes. i.e (azr=11+1). 6

7 { azr=11,azr for (azr=11,azr<=20,azr=11+1) expression update initialization condition { Body of the loop } 7

8 #include void main ( ) { int azr; clrscr ( ); for(azr=5;azr<=45;azr=5+1) { printf(“%d\n”,azr); } getch(); } 8

9 Then we put “if” statement after the “for” statement. i.e  to get even numbers: { For (initialization ;condition ; expression update) if (azr%2==0); }  to get odd numbers the if statement should be if (azr%2!=0). 9

10 #include void main( ) { int amb; clrscr( ); { for (amb=20;amb<=40;amb=amb+1) if (amb%2==0); } printf (“%d\n”,amb); getch(); } 10

11 #include void main( ) { int X; clrscr( ); { for (X=9;X<=35;X=X+1) if (X%2!=0); } printf (“%d\n”,X); getch(); } 11


Download ppt " An instruction or group of instructions.  Computer executes program repeatedly for specified number of times. Or until some terminating conditions are."

Similar presentations


Ads by Google