Pages

Friday, July 31, 2020

INTRODUCTION OF LOOP



Loops are also known as “Iterative statements” because every loop repeats it's body part until the loop’s condition would be true.
TYPES OF LOOPS IN C
In C language there are three types of loops available, which are described below.

1While loop

2. Do while loop
3. For loop


PARTS OF LOOP
A loop can be divide in the following three sub parts. 

1. Initialization: This part is responsible to initialize the loop’s variable.               

Example (int a=0)

2. Test condition: This statement is used to implement the test criteria and responsible to stop Loop’s execution.  Example while (a<10)


3. Increment or Decrement: These statements are used to change the value of loop’s variable.

Increment Examples
a++, a=a+1, a=a+2

Decrement Examples
a--, a=a-1, a=a-2

Increment and decrement statements can be also classify in two sub categories.
Pre increment (Example: ++a)
Post increment (Example: a++)

An example of pre and post increment 
int a=10
printf(“%d”,a++);

printf(“%d”,++a);
a=a+2;
printf(“%d,a);

- - - OUTPUT - - -
10
12
14

No comments:

Post a Comment