If Else in C++


Prev Tutorial Next Tutorial


If Else in C++

In general it can be used to execute one block of statement among two blocks, in C++ language if and else are the keyword in C++.

images

Syntax

if(condition)
{
........
statements
........
}
else
{
........
statements
........
}

In the above syntax whenever condition is true all the if block statement are executed remaining statement of the program by neglecting else block statement. If the condition is false else block statement remaining statement of the program are executed by neglecting if block statements.

Example

#include<iostream.h>
#include<conio.h>

void main()
{
int time=10;
clrscr();
if(time>12)
{
cout<<"Good morning";
}
{
cout<<"Good after noon";
}
getch();
}

Output

Good morning

Prev Tutorial Next Tutorial

Advertisements




Download Projects

Advertisements

Download WhatsApp Status Video

Buy This Ad Space Only $50 per Month, Ad Size 300X250