Looping statement


A Loop executes the sequence of statements many times until the stated condition becomes false. the statement that help us to execute a set of statements repeatedly are called loop control statements.

Increment Operator

++ is an increment operator. This is a unary operator. It increments the value of a variable by one.

The increment operator is classified into two categories as:-

Post-increment

If the increment operator ++ is placed immediately after (post) the operand then the operator is called post increment. As the name indicates post increment means increment after (post) the operand value is used so operand value is used first and then the operand value is incremented by 1.

W.A.P for Post-increment.

#include<stdio.h>
#include<conio.h>
void main()
 {
  int i=20,b;
  b=i++;
  printf(“%d”,i);
  printf(“%d”,b);
 }

Output

20 21

Pre-increment

If the increment operator ++ is placed before (pre) the operand then the operator is called Pre increment. As the name indicates pre increment means increment before (pre) the operand value is used, So operand value is incremented by 1 and this incremented value is used.

W.A.P for Pre-increment.

#include<stdio.h>
#include<conio.h>
void main()
 {
  int i=20,b;
  b=++i;
  printf(“%d”,i);
  printf(“%d”,b);
 }

Output

21 21

Decrement Operator

-- is a decrement operator. This is a unary operator. It decrement the value of a variable by one.

The decrement operator is classified into two categories as :-

Post-decrement

If the decrement operator -- is placed immediately after (post) the operand then the operator is called post decrement. As the name indicates post decrement means decrement after (post) the operand value is used so operand value is used first and then the operand value is decrement by 1.

W.A.P for Post-decrement

#include<stdio.h>
#include<conio.h>
void main()
  {
  int i=20,b;
  b=i--;
  printf(“%d”,i);
  printf(“%d”,b);
 } 

Output

19  20

Pre-decrement

If the decrement operator -- is placed before (pre) the operand then the operator is called Pre decrement. As the name indicates pre decrement means decrement before (pre) the operand value is used, So operand value is decrement by 1 and this decrement value is used.

W.A.P for Pre-decrement.

#include<stdio.h>
#include<conio.h>
void main()
 {
  int i=20,b;
  b=--i;
  printf(“%d”,i);
  printf(“%d”,b);
 }

Output

19 19

Types of loop