Conteúdo do Curso
Introduction to PHP
Introduction to PHP
Else Statement
An if
can be followed by an optional else
block. The else
block will execute if the Boolean expression tested by the if block evaluates to false
.
Let's consider a example:
main
<?php $age = 17; if ($age >= 18) { echo "You're an adult"; } else { echo "You're not an adult yet."; } ?>
In the example above, the age < 18, so the if code block hasn't been executed. The else
code block executes when the if condition is false
.
The else
syntax is like the if
syntax without a condition and parentheses ( )
.
Swipe to show code editor
Fill in the blanks in the code to check the identity of variables $var1
and $var2
using the if ... else
construct.
Obrigado pelo seu feedback!
Else Statement
An if
can be followed by an optional else
block. The else
block will execute if the Boolean expression tested by the if block evaluates to false
.
Let's consider a example:
main
<?php $age = 17; if ($age >= 18) { echo "You're an adult"; } else { echo "You're not an adult yet."; } ?>
In the example above, the age < 18, so the if code block hasn't been executed. The else
code block executes when the if condition is false
.
The else
syntax is like the if
syntax without a condition and parentheses ( )
.
Swipe to show code editor
Fill in the blanks in the code to check the identity of variables $var1
and $var2
using the if ... else
construct.
Obrigado pelo seu feedback!
Else Statement
An if
can be followed by an optional else
block. The else
block will execute if the Boolean expression tested by the if block evaluates to false
.
Let's consider a example:
main
<?php $age = 17; if ($age >= 18) { echo "You're an adult"; } else { echo "You're not an adult yet."; } ?>
In the example above, the age < 18, so the if code block hasn't been executed. The else
code block executes when the if condition is false
.
The else
syntax is like the if
syntax without a condition and parentheses ( )
.
Swipe to show code editor
Fill in the blanks in the code to check the identity of variables $var1
and $var2
using the if ... else
construct.
Obrigado pelo seu feedback!
An if
can be followed by an optional else
block. The else
block will execute if the Boolean expression tested by the if block evaluates to false
.
Let's consider a example:
main
<?php $age = 17; if ($age >= 18) { echo "You're an adult"; } else { echo "You're not an adult yet."; } ?>
In the example above, the age < 18, so the if code block hasn't been executed. The else
code block executes when the if condition is false
.
The else
syntax is like the if
syntax without a condition and parentheses ( )
.
Swipe to show code editor
Fill in the blanks in the code to check the identity of variables $var1
and $var2
using the if ... else
construct.