If Statement

Google Advertisements

Prev Tutorial Next Tutorial


if-then Statement

if-then is most basic statement of Decision making statement. It tells to program to execute a certain part of code only if particular condition or test is true.

Syntax

if(condition)
{
..........
..........
}

Example

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

void main()
{
int a=10;
if(a<10)
{
cout<<"a is less than 10";
}
getch();
}

Output

a is less than 10
If Statement
  • Constructing the body of "if" statement is always optional, Create the body when we are having multiple statements.
  • For a single statement, it is not required to specify the body.
  • If the body is not specified, then automatically condition part will be terminated with next semicolon ( ; ).

else

It is a keyword, by using this keyword we can create a alternative block for if part. Using else is always optional i.e, it is recommended to use when we are having alternate block of condition.

In any program among if and else only one block will be executed. When if condition is false then else part will be executed, if part is executed then automatically else part will be ignored.

Syntax

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

Example

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

void main()
{
int age=40;
if(a<18)
{
cout<<"you are child";
}
else
{
cout<<"you are young";
}
getch();
}

Output

you are young

Prev Tutorial Next Tutorial

Google Advertisements

Buy This Ad Space @$50 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 8076671483

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

Cloud computing is the on demand availability of computer system resources, especially data storage and computing power, without direct active management by the user. Cloud Computing Tutorial

College Projects Related to Java, AWT, C Projects for College, C++ Projects for College, Android Projects. Download Java C C++ Projects

Download Projects

Adsense Advertisements


Buy This ads Space 8076671483

Buy This Ad Space @$120 per Month, Ad Size 300X600 Contact on: hitesh.xc@gmail.com or 8076671483 Try this Keyword C++ Programs