Loop in c


What is Loop


In programming, a loop is a sequence of statement that used for repeated of statement until a specific condition not reached.
By the example, we can understand in an easy way without using loop


#include <stdio.h> #include <conio.h> void main() { int x=10; printf("Hi how are your"); }

Suppose that you want to print 10,20,100,1000 times then just think it’s possible but very difficult to type or copy-paste. By using loop we can print many types only two or three line of code.
There are three types of loop used in c.


  1. for

  2. while

  3. do while

For Loop In C

or loop used for executes for a group of statement repetition until condition not reached. First, initialize then check print statement and after increment/decrement then check a condition and again print statement.

the syntax of - for loop in c.


for(initilization;condition;incr/decr)

{

statement/expression;

}


A simple example of - for loop in c.
Print Codeverb.com message for 5 times by using for loop


#include <stdio.h>

#include<conio.h>

void main(){

int i;

clrscr();

for(i=1;i<=5;i++)

{

printf>(“Codeverb.com %d\n”,i);

}

getch();

}


Output
Codeverb.com 1
Codeverb.com 2
Codeverb.com 3
Codeverb.com 4
Codeverb.com 5

Just look here we do not repeat statement Codeverb.com but only two or three lines of code we are printing here for 5 times Codeverb.com messages