C Programs - Loops


While programming we usually come across a requirement where we want to execute a block of code repetitively.
Loops help us to achieve such functionality.

A loop executes a block of code until the condition given to it becomes false.

Basically there are three types of loop in C language

  1. for loop
  2. while loop
  3. do-while loop

for loop syntax

for (initialization; condition; increment/decrement)
{
  // code
}

while loop syntax

while (condition)
{
  // code
}

do-while loop syntax

do
{
  // code
} while(condition);

List of programs

  1. C program to print all natural numbers from 1 to n
  2. C program to print all natural numbers in reverse
  3. C program to print alphabets from a to z
  4. C program to print all even numbers
  5. C Program to print all odd numbers
  6. C Program to find sum of all natural numbers
  7. C Program to find sum of all even numbers
  8. C Program to find sum of all odd numbers
  9. C Program to count number of digits in a number