Control Statements
Control Statements
Chapter 02
Contol Statements
Flow Control / Control flow: the order in which statements
are executed.
- It is typically sequential but may be diverted to other paths
by branch statement.
- C++ provides different control statements
1. Conditional Statement
2. Looping / Iteration statement
3. Other statements
Conditional Statements
1. If Statement
- execute statements depending on a condition being staisfied.
- syntax: if ( expression / condition )
statement;
This statement executes if and only if the
expression inside the parenthesis results
to true / condition becomes true
- the syntax above is used if you want to execute single statememt for
the condition.
- If you want to execute more than 1 statement when
condition/ expression is true, use the syntax below:
if (expression)
{
statement1; you surround your statements
with open and close curly
statement2; bracket {} (block statement
}
- If you want to execute statement if the condition is not true:
syntax: if (expression)
statement1; statement1 wil be executed if
the expression/condition is true
else
statement2;