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

Contenido del 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

bookif Statement

if Statement

An if statement is a construct that allows you to execute a code block if a specific condition is met.

The condition is an expression that evaluates to a bool value, which can be true or false. If the condition is true, the block of code is executed. If the condition is false, the block of code is skipped.

Syntax

The syntax of the conditional operator is so simple: if keyword, condition in the parentheses ( ) and a code block in the curly brackets { }.

The open curly bracket { } opens the code block, and the close curly bracket symbol closes it.

Example 1

dart

main

copy
123456
void main() { var num=5; if (num>0) { // 5 > 0 ? print("number is positive"); // print if it's `true` } }

The condition was confirmed and the block of code worked.

Example 2

dart

main

copy
123456
void main() { var num = 10; if (num.isNegative) { // 10 < 0 ? print("number < 0"); // print if it's `true` } }

The condition was not confirmed, and the code block did not work.

Task

What should be put instead of "?" so the program works correctly?

What should be put instead of "?" so the program works correctly?

Selecciona la respuesta correcta

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 3. Capítulo 1
We're sorry to hear that something went wrong. What happened?
some-alt