While Loop in C with Example

While Loop in C with Example
  • while is the relational or logical expression that will have the value of true or false.
  • When this statement is executed, the computer will evaluate the value of the condition.
  • If the evaluated value is true, then the block of statement is executed and is repeated until the value of the condition is false.

Print natural numbers from 1 to n using while loop in C language

#include <stdio.h> 
main()
{
int i, n;
printf("Enter the value to n:");
scanf("%d",&n);
//while loop to print the numbers
while(i<=n)
{
i++;
printf("\n %d",i);
}
}

--

--

Hi, This is Biplab and I am web developer well versed in PHP and other open source technologies. I am here to share my experience with the community.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Bipsmedium

Bipsmedium

25 Followers

Hi, This is Biplab and I am web developer well versed in PHP and other open source technologies. I am here to share my experience with the community.