Conditional Statements In C++ Examples

Conditional Statements In C++ Examples

The statements of a computer program are executed one after the other in order in which they are written. This is known as sequential execution of the program.
The order of execution of the statements in a program can be changed. This is done with the help of conditional statements.

The conditional statements are used to execute or ignore a set of statements after testing a condition . The conditional statements are also called selection statements.

Example:


The following program  executes a single statement if the given condition is true.

#include<iostream.h>
main()
{
int a, b;
a=100;
b=50;
if(a>b)
cout<<"Islamabad"<<endl;
cout<<"OK"<<endl;
}

OUTPUT:

Islamabad
OK

Creative Commons License
Pakistan How by Tahira Aijaz is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.