Menu
Coddy logo textTech

Logical NOT

Part of the Fundamentals section of Coddy's Dart journey — lesson 25 of 94.

The logical NOT operator (!) reverses boolean values, turning true to false and vice versa.

void main() {
  bool isRaining = true;
  bool isNotRaining = !isRaining;
  
  print('Is it raining? $isRaining');
  print('Is it not raining? $isNotRaining');
}

Output:

Is it raining? true
Is it not raining? false

It's useful for checking negative conditions and can combine with other logical operators.

challenge icon

Challenge

Easy

Create a program that demonstrates the Logical NOT (!) operator in Dart:

  1. Declare a boolean variable isRaining and set it to true
  2. Declare a boolean variable hasUmbrella and set it to false
  3. Create a new boolean variable willGetWet that is true if it's raining AND the person does NOT have an umbrella (use the ! operator)
  4. Create another boolean variable canGoOutside that is true if it's NOT raining OR the person has an umbrella (use the ! operator)
  5. Print all four variables with the EXACT following format:
Is it raining? true
Do you have an umbrella? false
Will you get wet? true
Can you go outside? false

Your output must match this exact format.

Try it yourself

void main() {
  // Declare your boolean variables here
  bool isRaining = ?;
  bool hasUmbrella = ?;
  
  // Calculate willGetWet using logical NOT with AND
  bool willGetWet = ?;
  
  // Calculate canGoOutside using logical NOT with OR
  bool canGoOutside = ?;
  
  // Print the variables with labels
  print("Is it raining? $isRaining");
  print("Do you have an umbrella? $hasUmbrella");
  print("Will you get wet? $willGetWet");
  print("Can you go outside? $canGoOutside");
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals