If-else Statement in C++ | Topic 9 | VU Insider



As we have seen in If statement, the statement is executed when the condition is true. If the condition is false then statement will be skipped.

If/else structure allow us to specify another statement when the condition is false.

Syntax for IF-ELSE Statement:
If (condition)
statement or group of statements
else
statement or group of statementscode-box


Example for IF-ELSE Statement:
In easy english;
If (store is open)
Bring some groceries
else
Bring a Pizzacode-box


Another example for IF-else Statement: If ( Ali_age > Asif_age ) {
cout<<"Ali is older then Asif";
}
else {
cout<<"Asif is older than Ali";
} code-box


Note: Logical operators AND(&&) and OR(||) can also be used in if/else statement.

Post a Comment

Previous Post Next Post