DEV Community

Saina
Saina

Posted on

Exploring Dart: Datatypes, Conditional Statements, and Operators

Datatypes:
Numbers: Dart supports integers and doubles. Integers represent whole numbers, while doubles represent floating-point numbers.

Strings: Strings are sequences of characters, enclosed within single (' ') or double (" ") quotes.

Booleans: Booleans represent two values: true and false, used for logical operations.

Lists: Lists are ordered collections of objects. They can be created using square brackets ([ ]) and can contain elements of different datatypes.

Maps: Maps are collections of key-value pairs, where each key maps to a value.

Conditional Statements:
if-else: Executes code based on a true/false condition.

int num = 10;
if (num > 0) {
  print("Number is positive");
} else {
  print("Number is not positive");
}

Enter fullscreen mode Exit fullscreen mode

Switch Statements: Switch statements allow a program to execute different blocks of code based on the value of a variable.

String fruit = 'apple';
switch (fruit) {
  case 'apple':
    print('Selected fruit is an apple');
    break;
  default:
    print('Unknown fruit');
}
Enter fullscreen mode Exit fullscreen mode

Operators:
Arithmetic: Addition (+), Subtraction (-), Multiplication (*), Division (/), Modulus (%).
Assignment: Assign (=).
Comparison: Equal to (==), Not equal to (!=), Greater than (>), Less than (<), Greater than or equal to (>=), Less than or equal to (<=).
Logical: Logical AND (&&), Logical OR (||), Logical NOT (!).

int a = 10;
int b = 5;
int maxValue = (a > b) ? a : b;
print('The maximum value is $maxValue');

Enter fullscreen mode Exit fullscreen mode

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay