Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Bool, Equality and Relational Operators | Variables and Data Types
Introduction to Dart

Bool, Equality and Relational OperatorsBool, Equality and Relational Operators

Bool

We already know:

bool is a data type that can have two values: true or false. It is used to store logical values.

Here we have created a variable of data type bool with value true.

Here we have created a variable of data type bool with value false.

Equality and Relational Operators

In the this section, you will use these operators in conditional expressions to make decisions in the program. For example, you can check whether the user has entered the correct password using the equality operator, or determine if a person has access to a specific resource based on their age (as in the example with user age >= 18 ). In such cases, the result of the comparison becomes a bool value, which helps you make decisions in your program based on conditions.

OperatorMeaning
==equal
!=Not equal
>Greater than
<Less than
>=Greater than or equal to
<=Less than or equal to

In this сhapter, we will learn how to store a bool value that will be computed based on whether the condition is true or false.

Examples

dart

main.dart

10 > 2 is a true statement, so we see the result as true.

dart

main.dart

The variables day1 and day8 store the same values, so we get true as a result of the comparison.

Note

There are two equal (==) signs here because a single equal sign (=) has a completely different meaning. It is used for assignment and cannot (and does not make sense) to be used in if blocks.

Data Type Checking

The following operators do not check the value of the variable. They check the data type of the value.

OperatorMeaning
istrue if the value has the specified type
is!false if the value has the specified type
dart

main.dart

We get false because 4.2 is of the double type.

Tasks

1. 4 != 5
2. 6 <= 6 + 3
3. 4 == 2 + 2
4. var test = 33 is String;

4 != 5

Виберіть правильну відповідь

6 <= 6 + 3

Виберіть правильну відповідь

4 == 2 + 2

Виберіть правильну відповідь

var test = 33 is String;

Виберіть правильну відповідь

Все було зрозуміло?

Секція 2. Розділ 4
course content

Зміст курсу

Introduction to Dart

Bool, Equality and Relational OperatorsBool, Equality and Relational Operators

Bool

We already know:

bool is a data type that can have two values: true or false. It is used to store logical values.

Here we have created a variable of data type bool with value true.

Here we have created a variable of data type bool with value false.

Equality and Relational Operators

In the this section, you will use these operators in conditional expressions to make decisions in the program. For example, you can check whether the user has entered the correct password using the equality operator, or determine if a person has access to a specific resource based on their age (as in the example with user age >= 18 ). In such cases, the result of the comparison becomes a bool value, which helps you make decisions in your program based on conditions.

OperatorMeaning
==equal
!=Not equal
>Greater than
<Less than
>=Greater than or equal to
<=Less than or equal to

In this сhapter, we will learn how to store a bool value that will be computed based on whether the condition is true or false.

Examples

dart

main.dart

10 > 2 is a true statement, so we see the result as true.

dart

main.dart

The variables day1 and day8 store the same values, so we get true as a result of the comparison.

Note

There are two equal (==) signs here because a single equal sign (=) has a completely different meaning. It is used for assignment and cannot (and does not make sense) to be used in if blocks.

Data Type Checking

The following operators do not check the value of the variable. They check the data type of the value.

OperatorMeaning
istrue if the value has the specified type
is!false if the value has the specified type
dart

main.dart

We get false because 4.2 is of the double type.

Tasks

1. 4 != 5
2. 6 <= 6 + 3
3. 4 == 2 + 2
4. var test = 33 is String;

4 != 5

Виберіть правильну відповідь

6 <= 6 + 3

Виберіть правильну відповідь

4 == 2 + 2

Виберіть правильну відповідь

var test = 33 is String;

Виберіть правильну відповідь

Все було зрозуміло?

Секція 2. Розділ 4
some-alt