Alternative Structures



In certain situations, it is necessary to execute instructions within a program only under certain conditions. Alternative structures (also known as decision structures) allow handling such situations.


The if Statement

The if statement is the most commonly used alternative structure.

Syntax

The if statement has two forms:


Variant 1

if( Expression )
    Statement1
else
    Statement2

Variant 2

if( Expression )
    Statement1

Observations


if(Expression) … 

if(Expression != 0) … 

Similarly, the following sequences are equivalent:


if(!Expression) … 

if(Expression == 0) … 

Accessibility Options

Color Contrast

Text Size

Text Spacing

Reading Aids