3/8/2020 While Loop in C Programming Language with Examples
PHP Training Login/Register
C Tutorial Home >> C Tutorial > C While loop
History of the C Language C While loop
Features of the C Language
How to Install C
« Previous Next »
First C program
C Program Flow While loop in C
The While loop in the C language is generally known as a pre-tested loop,
Printf and scanf in C
depending on a provided Boolean condition while loop allows a part of the code
Variables in C to be executed multiple times. While loop can also be seen as a repeating if
statement. The major use of the while loop lies in the case when the number of
Data Types in C
iterations are not known in advance.
C Keywords
Syntax of the while loop in the C language
Operators in C
Here is the syntax of the while loop in the C language:
Comments in C
while(condition)
Escape Sequence in C {
//code that is to be executed
Constants in C }
C If-else statements Here is the owchart of the while loop in the C language
C Switch Statement
C Loop Here are couple of examples of the while loop in the C
language
C While loop
1.In the following example, while loop is used to print the table of 1.
C do-while loop
C for loop
Type Casting in C
#include<stdio.h>
C Functions int main(){
int i=1;
C call By Value and Reference
while(i<=10){
printf("%d \n",i);
C Recursive Function
i++;
}
C Arrays
return 0;
}
C 2-Dimensional Array
Arrays to function in C Output :
1 2 3 4 5 6 7 8 9 10
Pointers in C
2. In this following example, while loop is used to print table for any provided
Double Pointers in C number by the user:
Arithmetic Pointer in C #include<stdio.h>
int main(){
Dynamic memory allocation in
int i=1,number=0,b=9;
C printf("Please enter a number of your choice: ");
scanf("%d",&number);
C Strings while(i<=10){
printf("%d \n",(number*i));
C Math Function
i++;
}
C Structure
return 0;
}
C Nested Structure
Output :
C Union Please enter a number of your choice: 20
20 40 60 80 100 120 140 160 180 200
C File Handling
C Preprocessor
https://www.phptpoint.com/while-loop-in-c/ 1/3
3/8/2020 While Loop in C Programming Language with Examples
C Preprocessor
Let's have a look at the properties of the while loop
PHP Training Login/Register
C Error Handling In order to check the condition, a conditional expression is used. Until the
provided condition is failed, the statements de ned within the while loop
C Command Line Arguments
will execute repeatedly.
Storage classes in C The condition will turn out to be true if it returns 0 and it will return non-
zero number, if the condition is false.
Macros In C
The condition expression is mandatory in the while loop.
C Programs
Users can run a while loop without a body.
C Interview Questions
Users can have more than one conditional expression in the while loop.
The braces are optional if the loop body contains only one statement.
Here are 3 examples of the while loop to give you a be er understanding of the
topic: Example 01
#include<stdio.h>
void main ()
{
int j = 1;
while(j+=2,j<=10)
{
printf("%d ",j);
}
printf("%d",j);
}
Output :
3 5 7 9 11
Example 02
#include<stdio.h>
void main ()
{
while()
{
printf("hi Phptpoint");
}
}
Output :
compile time error: while loop can't be empty
Example 03
#include<stdio.h>
void main ()
{
int x = 10, y = 2;
while(x+y-1)
{
printf("%d %d",x--,y--);
}
}
Output :
infinite loop
In nitive while loop in the C langauge
In the while loop, if the expression passed results in any non-zero value then the
loop will run for an in nite number of times.
while(1)
{
//statement
}
« Previous Next »
https://www.phptpoint.com/while-loop-in-c/ 2/3
3/8/2020 While Loop in C Programming Language with Examples
Popular Tutorials PHP Training Login/Register
About Quick Menu Tutorials Social
Icons
Blogs About Us Python Built-in Functions
Projects Privacy Policy Python Reference
Contact us Term and Condition JavaScript Date Object
Methods
Guest Post Of ine Training
JavaScript Array Reference
Live Support Development
JavaScript Math Reference
Live Support
Copyright © All Rights Reserved | Developed by Phptpoint.
https://www.phptpoint.com/while-loop-in-c/ 3/3