Header Responsive Ads

For loop in C++

for loop in c++

Loop is used when we need to execute a code block multiple times. For loop in C/C++ is very specialized while loop. What is loop? Loop as for loop is used to execute a specific block of code until a condition becomes false. For loop is the most frequently loop in C++.

Syntax of for loop

for(initialize loop counter; condition check; increment/decrement)
Block of code

First of all keyword “for” is written. Than inside parenthesis (---), there are three statements. In first statement, loop counter value is set only once. In second statement, condition is checked whether true or false. In third statement, loop counter in incremented / decremented. Note that there is semicolon (;) after first and second statement. Then body of for loop is written inside curly brackets { } and code block in body is executed based on condition.

Steps of for loop execution 

First Step: Loop counter is initialized with starting value and it executes only one time.

Second Step: For loop condition is checked whether it is true of false

Third Step: After second step, control directly goes inside curly bracket and executes body code block

Forth Step: In last step, loop counter is incremented or decremented

Write a C++ program to display table of a number upto a given maximum limit. Program will prompt the use to give number and maximum limit to which table of given number will be shown.

for loop
for loop
for loop output
for loop output

Post a Comment

Previous Post Next Post

In Article Ads 1 Before Post

In Article Ads 2 After Post