Dart 2.
0
Variables
1. int age = “17”; // Numbers
2. String name = “Paras”; // Text
3. double pi = “3.14”; // Numbers with Decimals
4. bool isBeginner = true; // If it is true or false Value
Programming Fundamentals
Basic Maths variables
1. Addition( + )
2. Subtraction( - )
3. Multiplication( * )
4. Division( / )
5. Reminder( % )
6. increment by one ( ++ )
7. decrement by one ( - - )
Comparison Operators
Equals To ( == ) , 5==5 → true,
Not equal To ( ! = ) 2=3 → true,
Greater Then, ( > ) 3>2 → true,
Less Then , ( < ) 2<3 →true,
Greater or equal to ( > = ) 5≥5 → true ,
Less or equal to ( < = ) 3 < = 7 → true,
Logical Operators
Dart 2.0 1
1. Add Operator ( && ) , Return true if both sides are true
2. OR Operator ( || ) , Return true if at least one side is
true,
3. Not Operator ( ! ) , Return the opposite value ,
Control Flow Statement
If Statement
If( condition ) {
do something
}
If else Statement
if ( condition ) {
do something
}
else {
other command in case condition is false
}
If else If Statement
if (condition ){
do something
} else if (another Condition )
{
do something
}else {do something
For Example :
Dart 2.0 2
String grade = “B”;
if (grade == “A”){
print(”Excellent”);
} else if(grade ==”b”){
print(”Good”);
}else{print(”Invalid input “);
Switch Statement
Switch(grade) {
case ‘A’:
print(”Excellent”);
break;
case ‘B’:
print(”Good!”);
break;
case ‘C’:
print(”Fair!”);
break;
default:
print(”Invalid”);
}
Loops
For loop
for( initialisation; condition; interaction){
do something
Dart 2.0 3
}
for example:
for ( int i=0; i≤5; i++ ){
print(i);
break; ⇒ break out of loop
continue ⇒ skip this current interaction
While loop
while ( condition ){
do something
}
for example:
int ( countDown =5;
while (countDown >0)
{
print(countDown);
Functions/Methods
we just looked at some cool blocks of code that gets things
done! we can organise these blocks of code into functions so
that we can reuse them easily.
‘void’ means that the function return nothing. This one for just
executes the code in the function.
Basic Function
voi greet(){
print(’Hello’);
Dart 2.0 4
}
greet();
Functions with parameters
void greetPerson( String name ){
print(’hello’+ name );
}
greetPerson(’Paras’);
Functions with return type
int add (int a , int b ){
int sum = a+b;
return sum;
int mySum = add(3,5);
print(mySum);
Data Structures
List: ordered collection of elements, can have
duplicates.
List<int> numbers = [ 1,2,3 ];
void printNumbers(){
for ( int i=0; i< numbers.length; i++){
print(numbers[i]);
printNumbers();
Sets: unordered list collection of unique elements
Set<String> uniqueNames = {”Paras”,”Noddy”};
Dart 2.0 5
Map: stored as key-value pairs
Map users = {
‘name’ = ‘Paras’,
‘age’ = ’17’,
‘height’= ‘6ft’,
}
print (users[name]);
Dart 2.0 6