C++ Control Structures

Introduction
There are three types of program flow controls, namely; Sequential, selective and repetitive program control.

Sequential
This is a program flow control where statements are evaluated and executed from top to bottom ( from first to last) one after the other.

Example: using namespace std; int main { //program to compute the surface area of a closed cylinder int radius, height = 10; const double pie = 3.1428; double sArea; cout<<"Enter the Radius \n"; cin>>radius; sArea = (2*pie * pow(radius,2)) + (2 * pie * radius * height)//using the power function to get the square of pie cout<<"The Surface area is = "< depending on the compiler version

The statements in the example above are executed from the first to last respectively.

Selective
The execution of the program code within these control structures is determined by the result of the condition after evaluation.

if
This is a selective control that has only one option. The statements within it are executed if the condition evaluates to true otherwise nothing happens. Syntax: if (condition){statements;} Example 1: if(mark>80){cout<<"Distinction \n";} Example 2: int main { int a, b, temp; cout<<"Enter two values"<>a>>b; if (a>b){ temp=a; a=b; b=temp; } return 0; }
 * 1) include

Repetitive
for

while

do..while