What are the different types of Conditional Statements?

Types of Conditional Statements:
1. If statement: It executes the statements if the condition within it is true.
Syntax:
if (condition)
{
Statements;
}

2. If else statement: If else statement executes the statements within the if block if condition is true but if the condition is false then it executes statements that are within the else block.
Syntax:
if(condition)
{
Statements;
}
else
{
Statemments;
}

3. Else if statement: Else if statement is used to execute the statements by checking multiple conditions. If any one condition out of the multiple conditions is true then statements within that block executes. If no condition is true then statements in else block executes.
Syntax:
If(condition 1)
{
Statement block1;
}
else if (condition 2)
{
Statement block 2;
}
else if (condition n)
{
Statement block n;
}
else
{
Statements;
}
4. Switch statement: It is used to execute the statements by checking the multiple conditions or choices that are available. Switch statement uses multiple cases. A particular case executes if its value matches the value of switch variable.
Syntax:
Switch (variable)
{
case item1: statements 1;
Break;
case item2: statements 2;
Break;

default: statements;
}

More Questions

Leave a Reply

Word Verfication * Time limit is exhausted. Please reload CAPTCHA.