Saturday, September 19, 2020

Explain for statement flow chart with example

* for statement :


The for loop is entry controlled loop that provides more concise structure.

The general form of for loop is 

for(initialization;test-condition;increment/decrement)

{

      body of loop

}

* Flow chart :


The execution of the for loop is as follow

▪️ initialization of the control variable is done first,using assignment statement such a i = 1.

the variable[ i ] is known as loop-control variable.

▪️ the value of the variable is tested using the test-condition.

the test condition is a relational expression such as i<=10 that determines when the loop will exit.

If condition is a true,the body of the loop is executed; otherwise loop is terminnated and the execution continues with the statement that immediatly follows the loop.

▪️ when the body of the loop is executed, the control is transferred back to the for statement after evaluating last statement in the loop.

Now the control variable is incremented ordecremented using an assignment statement such as i=i+1 or i=i-1 etc and the new value is again tested to see wheather it satisfies the loop condition.

This process continues till test condition becomes false. 

consider the following example :

for(x=1; x<=10, x++)

{

        printf("%d",10*x);

}

In above example table of 10 will be displayed.





2 comments:

Object Paradigm Oriented Programming in C++ / object oriented programming / History of C++/ paradiagram in c++/C devolop, Operating System, Unix operating system, Assembly language, popular in world, Programming language.

  Object Paradigm Oriented Programming  Two programmers, Brian Kernighan and Dennis Ritchie developed a new language called C, in 1972.  C l...