Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Bool, Equality and Relational Operators in Dart | Variables and Data Types in Dart
Introduction to Dart

book
Bool, Equality and Relational Operators in Dart

Bool

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

javascript
bool adult = true;

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

javascript
bool married = false;

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

Equality and Relational Operators

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. In such cases, the result of the comparison becomes a bool value, which helps you make decisions in your program based on conditions.

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

copy
void main() {
bool info = 10 > 2; // `true`
print(info);
}
1234
void main() { bool info = 10 > 2; // `true` print(info); }

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

dart

main

copy
void main(){
String day1 = 'Monday';
String day8 = 'Monday';
print(day1 == day8); // `true`
}
12345
void main(){ String day1 = 'Monday'; String day8 = 'Monday'; print(day1 == day8); // `true` }

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

Data Type Checking

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

dart

main

copy
void main() {
print(4.2 is int); // `false`
}
123
void main() { print(4.2 is int); // `false` }

We get false because 4.2 is of the double type.

1. Consider the expression (4 != 5) and determine whether they evaluate to true or false.

2. Consider the expression (6 <= 6 + 3) and determine whether they evaluate to true or false.

3. Consider the expression (4 == 2 + 2) and determine whether they evaluate to true or false.

4. Consider the expression (var test = 33 is String;) and determine whether they evaluate to true or false.

question mark

Consider the expression (4 != 5) and determine whether they evaluate to true or false.

Select the correct answer

question mark

Consider the expression (6 <= 6 + 3) and determine whether they evaluate to true or false.

Select the correct answer

question mark

Consider the expression (4 == 2 + 2) and determine whether they evaluate to true or false.

Select the correct answer

question mark

Consider the expression (var test = 33 is String;) and determine whether they evaluate to true or false.

Select the correct answer

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

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 2. Розділ 5

Запитати АІ

expand
ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

We use cookies to make your experience better!
some-alt