While loop in c++ with example

While loop is simplest loop in c++

Syntax:-

while(condition)
{
Body of the loop
}
Statement;

Note:-

# If body of loop is only one statement than braces ({}) are not needed.
# Body of the loop may have one or more statement.

Execution:-

In while loop 1st condition will check if condition is true than body of the loop will executed. After body of the loop is execute, the condition is again tested if condition is true than again body of loop is executed, this process is repeated until condition is true. When condition is false than statement next to while loop is executed.

Example:-

Program to count N number


Program to display N even number



Previous Code:-
For loop

List Code:-
C++ Codes

Next Code:-
Do while loop

C++ Programs
List of c++ Programs

One Comment

  1. Can you solve this problem?
    Create a program that will accept a number and print the product of the integers.
    Use while loop, do while llop and for loop.
    print the elment of an integer:
    Ex Input:5
    Output elements= 1 2 3 4 5
    Product=120

    ReplyDelete

Add your comments here

Back to Top