2. In computer science, control flow (or
alternatively, flow of control) refers
to the specification of the order in
which the individual statements,
instructions or function calls of an
imperative program are executed or
evaluated.
4. Statements
Simple Statements: These are single statements. Eg:
If(a>0)
cout<<a;
Compound Statements: It is a group of statements separated from each other by a
semicolon(;). This group of statements is also called a block of code enclosed within a pair
of curly braces { }. Its significance is that the group of statements under curly braces is
treated as one unit. Eg:
If(a>0)
{
b==a;
cout<<b;
}
5. Precedence of operators
In C++ and other programming languages, compiler works according to
certain priority and order of operators which is also termed as precedence
of operators.
6. Selection (If else)
If else statements are used to control flow of compiler on the basis of given
condition is true or false. If the condition is true then it executes the if
block otherwise moves out of the block.
Syntax:
If(condition)
{
code block;
}
7. If-else
This is in addition to If statement. It includes ‘else’ block after ‘if’ block. If the ‘if’
block condition is false then the compiler moves in else block or vice versa.
Syntax:
If(condition)
{
code block;
}
else
{
code block;
}
10. Switch Case
This statement is used when we have to
select one option out of many
alternatives. It is a multi branch
statement that makes the control to
jump to one of the several statements
based on the value of an integer
variable or an expression. The general
form of the switch is:
11. Iteration Statement
Iteration statements cause statements (or compound
statements) to be executed zero or more times, subject
to some loop-termination criteria. When these
statements are compound statements, they are
executed in order, except when either
the break statement or the continue statement is
encountered.
12. While loop
It is executed repeatedly until or unless the condition is false. There must
be some loop terminating or updating conditions inside the loop code
block to avoid infinite looping.
Syntax:
while(expression)
{
statement;
statement;
}
13.
14. For Loop
It is similar to while loop except it contains three
parts in its expression i.e. initialization, condition,
updation in variable.
Syntax:
for(initialization; condition; updation)
{
statement;
}
15.
16. Jump Statements:
Break statement: The break statement ends execution of the nearest
enclosing loop or conditional statement in which it appears. Control passes
to the statement that follows the end of the statement, if any.
Continue Statement: Forces transfer of control to the controlling
expression of the smallest enclosing do, for, or while loop.
Exit Statement: The exit() function stops the program. exit_code is passed
on to be the return value of the program, where usually zero indicates
success and non-zero indicates an error.