lec2-2
lec2-2
Lecture 2
Dr.Sara Shehab
Getting Started
void main() {
print("Hello World!");
}
Identifiers
void main( ){
var heart_symbol = '\u2665';
var laugh_symbol = '\u{1f600}';
print(heart_symbol);
print(laugh_symbol);
}
Symbol
• +
•-
•*
•/
•%
• Unary –
Arithmetic Operators
void main(){
print("Example of Assignment operators");
var n1 = 10;
var n2 = 5;
print("n1+n2 = ${n1+n2}");
print("n1-n2 = ${n1-n2}");
print("n1*n2 = ${n1*n2}");
print("n1/n2 = ${n1/n2}");
print("n1%n2 = ${n1%n2}");
}
Increment and Decrement
• =
• +=
• -=
• *=
• ~/=
• %=
Relational Operators
• ==
• !=
•<
•>
• <=
• >=
Bitwise Operators
• AND &
• OR |
• EX-OR ^
• >>
• <<
• ~
Type Test Operators
• as
– It is used for typecast.
• is
– It returns TRUE if the object has specified
type.
• is!
– It returns TRUE if the object has not specified
type.
Type Test Operators
void main()
{
var num = 10;
var name = "Skillologies";
print(num is int);
print(name is! String );
}
Logical Operators
• &&
• ||
•!
Conditional Operators
• Syntax 2 -
exp1 ??expr2
If the exp1 is not-null, returns its value,
otherwise returns the exp2's value.
Conditional Operators
void main() {
var x = null;
var y = 20;
var val = x ?? y;
print(val);
}
Conditional Operators
• void
main()
{ var a
= 30;
• var output = a > 38 ? "value greater than 10":"value
lesser than equal to 30";
• print(output);
• }
The parse()
•