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

bookBool, Equality and Relational Operators in Dart

Bool

The bool data type can store only two values: true or false. It is used for logical expressions and conditions.

file1.

file1.

copy
1234
void main() { bool adult = true; bool married = false; }

This variable has the data type bool and stores the value true. This variable has the data type bool and stores the value false.

Equality and Relational Operators

You use these operators in conditional expressions to make decisions in a program. For example, you can check whether a user entered the correct password using the equality operator, or determine if a person has access to a resource based on their age. In such cases, the result of the comparison is a bool value, which helps you control the program flow based on conditions.

main.dart

main.dart

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

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

main.dart

main.dart

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

Note
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) be used for boolean expressions.

Data Type Checking

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

main.dart

main.dart

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

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

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

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 2. Kapitel 5

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

Awesome!

Completion rate improved to 4.55

bookBool, Equality and Relational Operators in Dart

Swipe um das Menü anzuzeigen

Bool

The bool data type can store only two values: true or false. It is used for logical expressions and conditions.

file1.

file1.

copy
1234
void main() { bool adult = true; bool married = false; }

This variable has the data type bool and stores the value true. This variable has the data type bool and stores the value false.

Equality and Relational Operators

You use these operators in conditional expressions to make decisions in a program. For example, you can check whether a user entered the correct password using the equality operator, or determine if a person has access to a resource based on their age. In such cases, the result of the comparison is a bool value, which helps you control the program flow based on conditions.

main.dart

main.dart

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

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

main.dart

main.dart

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

Note
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) be used for boolean expressions.

Data Type Checking

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

main.dart

main.dart

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

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

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

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 2. Kapitel 5
some-alt