Introduction
C Programming
C Advanced
Important C Programs
Modal Box
Tutorials
C is a very powerful and widely used language. It is used in many scientific programming situations. It forms (or is the basis for) the core of the modern languages Java and C++. It allows you access to the bare bones of your computer.C++ is used for operating systems, games, embedded software, autonomous cars and medical technology, as well as many other applications. Don't forget to visit this section...
Loops in C Language
Suppose block of statements has to be executed repeatedly, then instead of writing those statements multiple times, loops are used.
The looping statements are used to execute a single statement or block of statements repeatedly until the given condition is FALSE. So if i have to print myname 100 times, then instead of writing printf hundred times, we can use loop with condition that executes 100 times.
Types of the Loops in C :
- while statement
- do-while statement
- for statement
Using while loop the body executes till the condition is true .
Syntax for while loop
while(condition here)
{
/*statement to be executed for true condition*/
}
Example
Print no. from 1 to 100
#include<stdio.h>
#include<conio.h>
int main()
{
int i=1;
while(i<=100)
{
printf("%d ", i );
i++;
}
}
⇒ The above loop terminate when the value of i exceeds 100, so loop condition becomes false.
If condtion is always true, it means infinite looping is there.
#include<stdio.h> #include<conio.h> int main() { int i=1; while(i<=100) { printf("%d ", i ); } }
⇒ Here the value of i is not changing, so it is always true and loop becomes infinite loop .
Video/ C Introduction
Watch video in full size