If...Else Statements
If we wanted to add some default behavior to the if
statement, we can add an else statement to run the block of code when the condition evaluates to false
.
Example:
In the above example:
else
keyword is used following theif
statement.Has a code block that is wrapped around the curly braces
{}
.The code inside the
else
statement will execute when theif
statement evaluates tofalse
.
NOTE if..else
statement allows us to automate the yes-or-no questions, also known as binary decisions.
Example:
Last updated