Docsity

Lecture Notes on Program Flow Control | ECET 210, Study notes of Electrical and Electronics Engineering

Toggle sidebar
bg1
Program Flow Control
There are language Constructs which control how the execution of the program is to take place.
In other words these elements (Constructs) control the flow of the program.
Program Flow Control Elements:
1. Normal execution of the program is to execute sequentially line after line. (Built into the
C++ language).
2. Invoking a function (Calling a function).
3. if statement.
4. if …………………else statement.
5. switch statement.
6. while loop.
7. do……………………..while loop.
8. for loop.
pf3

Partial preview of the text

Download Lecture Notes on Program Flow Control | ECET 210 and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

Program Flow Control

There are language Constructs which control how the execution of the program is to take place.

In other words these elements (Constructs) control the flow of the program.

Program Flow Control Elements:

1. Normal execution of the program is to execute sequentially line after line. (Built into the

C++^ language).

2. Invoking a function (Calling a function).

3. if statement.

4. if …………………else statement.

5. switch statement.

6. while loop.

7. do……………………..while loop.

8. for loop.

Conditional structure: if and else

The if keyword is used to execute a statement or block only if a condition is fulfilled. Its form

is:

if (condition) { statement(s); }

Where condition is the expression that is being evaluated. If this condition is true, statement

is executed. If it is false, statement is ignored (not executed) and the program continues right

after this conditional structure.

For example, the following code fragment prints x is 100 only if the value stored in the x

variable is indeed 100 :

if (x == 100) cout << "x is 100";

If we want more than a single statement to be executed in case that the condition is true we can

specify a block using braces { }:

if (x == 100) { cout << "x is "; cout << x; }