You are on page 1of 13

Mobile computing lab1

Eng : hamada mostafa Eng : fatma mohammed


Course content

u Programming language ( Dart ) basics


u OOP in Dart
u Design layout
u APIs
u Design pattern
u Socket
Lab1 content

u Data type

u Control Flow

u Comment

u Operation

u Loops

u Function
Data type
u int: Represents integer values
int myInt = 10;
u double: Represents floating-point numbers
double myDouble = 3.14;
u num: Represents either an integer or a floating-point number
num myNum = 10; // Integer
num myNum2 = 3.14; // Double
u String: Represents a sequence of characters
String myString = 'Hello, Dart!’;
u bool: Represents boolean value
bool isDartFun = true;
u List: Represents an ordered collection of objects
List<int> numbers = [1, 2, 3, 4, 5];
List<String> names = ['Alice', 'Bob', 'Charlie’];
u Map: Represents a collection of key-value pairs
Map<String, int> ages = {
'Alice': 30,
'Bob': 25,
'Charlie': 35,
};
u dynamic: Represents a type that can change at runtime
dynamic dynamicVar = 10;
dynamicVar = 'Hello';
Control Flow
:
if statement switch statement:
u int x = 10; u int number = 3;
If (x > 5) { switch (number) {
print('x is greater than 5'); case 1: print('One’);
} else { break;
print('x is not greater than 5'); case 2: print('Two’);
} break;
case 3: print('Three’);
break;
default: print('Unknown number’);
break;
Comment

Single-line comments: Multi-line comments:

u // This is a single-line comment var u /*


This is a multi-line comment
It can span multiple lines
u number = 10; // This comment explains and is useful for longer planations
the purpose of the variable
u */
Operation

Arithmetic Operators : Logical Operators :


1. * and / 1. NOT (!)
2. + and - 2. AND (&&)
3. OR (||)
u void main() { u void main() {
int result = 10 + 5 * 2; bool result = true && false || true;
print(result); print(result);
// Output: 20 // Output: true
} }
loops
u for loop:
for (int i = 0; i < 5; i++) {
print('Index: $i');
}
u while loop:
int count = 0;
while (count < 5) {
print('Count: $count');
count++;
}
u do-while loop:
int count = 0;
do {
print('Count: $count');
count++;
} while (count < 5);
Functions

u Function without a return value


Syntax :
void functionName(parameters) {
// Function body
}
EX :
void greet(String name) {
print('Hello, $name!');
}
u Function with a return value:
Syntax :
returnType functionName(parameters) {
// Function body
return value;
}

Ex :
int add(int a, int b) {
return a + b;
}
Quick task

u A phrase is a palindrome if, after converting all uppercase letters into lowercase
letters and removing all non-alphanumeric characters, it reads the same forward and
backward. Alphanumeric characters include letters and numbers.

u EX :
Input : “race a car”
Output: false

Input : “a man , a plane , a canal: panama”


Output : true
Thanks !

You might also like