While loop in C++

While loop in C++

While loop in C language, While is also a keyword of C language so it can’t use as a variable. Actually While name express, “execution will be continued until the provided condition is true” . We used curly brackets around the statement same as if statement. In simple words we can say, we enclosed the statement in curly brackets. Here is following structure of while loop.

While (Condition)
 {
 Statement
 }

Above structure shows that , In the while condition area you may use logical operators. If your condition or logical operator condition will be true, then program will be executed repeatedly,Until the statement will false.Lets take a meaningful example to understand the whole structure of while loop.

#include<iostream> // Header files
using namespace std; 
main()
{
  int Number; // Declare variable 
  cout<<"Please enter the first digit: ";
  cin>>Number;
  while(Number<10) // While loop structure 
  {
  	Number=Number+1;   // Increment in Number 
  	cout<<Number<<'n'; 
  }
}

We clearly describe the while loop in the above example as you seen, We made the simple program above, which work is typing the digits on specific limit. Make sure that You may use (Number<=10>, with equal sign then it will showing output from,initialize the digits and end on 11 because we are using increment formula Number=Number+1. You can use increment or decrements operators like as Number++, Number- -,Above the end of the example we use “n” new line tag in C language enclosed in double quotes. <<endl and n are the new line tags in C language. 

Flow Chart of While Loop

While loop in C

We Learn While loop in C Language in next lessons we will take other loops do while loop or for loop structure for more enhancement and advance tricks. Hope you understand the while loop structure, if you have any query feel free comment below.

0 0 votes
Article Rating
Subscribe
Notify of
guest

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
trackback

[…] do while loop in C recap the previous lesson.We seen that in our previous lesson the body of while loop does’t execute even a single time. we have read, if while loop condition false then program […]