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");
}
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');
}
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');
Top comments (0)