-moz-user-select:none; -webkit-user-select:none; -khtml-user-select:none; -ms-user-select:none; user-select:none;

Monday 23 March 2015

Example of While loop

Asalam o alikum. I hope you are enjoying good health by the grace of Allah Almighty.
In this previous blog,I have discussed about loops.Now,in this blog,I will discuss a simple example of While loop.

Remember that While loop is used to repeat a statement,etc if we do not know in advance how many times we want to repeat that statement,etc.So,the syntax of While loop is


Syntax

while(condition)
statement;

Or


while(condition)
{
statement(s);
}

Example 

Source code

khgamujtaba,C++

Output


khgamujtaba,C++

So,in this example,we have initialized the value of n.The initial value is 1 and we have used a while loop to repeat the statement "Happy Pakistan Resolution Day" for 5 times."n++" means to increment the value of n.The loop will continue to execute as long as the condition becomes false.

No comments:

Post a Comment