Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Else Statement | Conditional Statements
Introduction to PHP
course content

Conteúdo do Curso

Introduction to PHP

Introduction to PHP

1. First Acquaintance
2. Variables and Data Types
3. Conditional Statements
4. Arrays
5. Loops

bookElse 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:

php

main

copy
12345678
<?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 ( ).

Tarefa
test

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.

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 2
toggle bottom row

bookElse 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:

php

main

copy
12345678
<?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 ( ).

Tarefa
test

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.

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 2
toggle bottom row

bookElse 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:

php

main

copy
12345678
<?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 ( ).

Tarefa
test

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.

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

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:

php

main

copy
12345678
<?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 ( ).

Tarefa
test

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.

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Seção 3. Capítulo 2
Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
We're sorry to hear that something went wrong. What happened?
some-alt