Lecture 3 Dart
Lecture 3 Dart
CET-222
SIDRA KHATOON
DART – LOOPS
• For loop in Dart is similar to that in Java or any other language and also
the flow of execution is the same as that in Java or any other language.
• Syntax:
for(initialization; condition; text expression){
// Body of the loop
}
CONTROL FLOW
• The first is executed only once i.e in the beginning while the other
three are executed until the condition turns out to be false.
EXAMPLE
• The body of the loop will run until and unless the condition is true.
• Expression:
while(condition){
text expression;
// Body of loop
}
EXAMPLE
void main()
{
var a = 4;
int i = 1;
while (i <= a) {
print('Hello World!');
i++;
}
}
DO-WHILE LOOP
• The body of the loop will be executed first and then the condition is
tested.
• Syntax:
do{
text expression;
// Body of loop
}while(condition);
EXAMPLE
void main()
{
var a = 4;
int i = 1;
do {
print('Hello World!');
i++;
} while (i <= a);
}
DART – FUNCTIONS
• Dart provides us with the facility of return value: defines the value
using functions in its program. to be returned from the function.
class class_name {
// Body of class
}
CLASSES IN DART(CONT.)
The body of the class consists of fields, constructors, getter and setter
methods, etc.
• Classes Fields are the variables which data for the objects. Let us check
with an Example:
class Student{
// Fields defining the
// Properties of Class
int? roll_no;
String? name;
}
2: CLASS METHODS IN DART