♦ C++ While Loop
♣ About C++ While Loop
While Loop is used to execute the associated code block until the provided expression holds the Boolean value True.Certain Expressions hold the True value for all time, in that case, there is an Infinite While Looping and external signal is required to break the While Loop.
♣ C++ While Loop Syntax
While Loop accepts a condition or a expression and iterates until that condition or expression is holding boolean value true.Below is the representation of While Loop Syntax.
Basic Syntax
while (expression) { // code for execution }
Syntax Explanation:
expression: logical expression which evaluates to true or false
♣ Example1: Calculate Sum of natural Numbers by While Loop in C++
In this example, Sum of N natural numbers is calculated by While Loop.. Example
Input:
Output:
♣ Example2: Finding Euler's Series value using While Loop in C++
In this example, value for Euler's series will be found using While Loop Example
Input:
Output: