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

Conteúdo do Curso

Introduction to Dart

Introduction to Dart

1. First Acquaintance with Dart
2. Variables and Data Types
3. Conditional Statements
4. List and String
5. Loops

book
if...else Statement

if...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.

Example

dart

main

copy
12345678
void main() { int age = 17; if (age >= 18) { print("You're an adult"); } else { print("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 ( )

Task

Write a condition for the if statement to check whether the variable is of type int.

dart

main

copy
12345678
void main() { var num = 7.0; if(___){ print('Type: int'); } else { print('Type: other type'); } }

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 2
We're sorry to hear that something went wrong. What happened?
some-alt