There are following types of conditional statements in C++:
- if statement
- if - else statement
- nested if-else statement
- if -else if ladder
- switch statement
1. If statement - The statements inside the body of “if” only execute if the given condition returns true. If the condition returns false then the statements inside “if” is not executed.
Syntax :
if (condition)
{
// Body of the loop.
// These statements will only execute if the condition is true.
}
Flow Diagram of if statement
Example of if statement in C++
#include <iostream.h>
#include<conio.h>
int main()
{int a=15,b=10;if(a<=b) //if condition statement{cout<<"Value of a is less than or equal to b."; //display output}getch();}
OUTPUT:
Value of a is less than or equal to b.
0 Comments
If you have any doubts , Please let me know.