Lecture 3 - Mobile App Development (1) PDF
Document Details
Uploaded by SmootherMoldavite2240
Dr. Samah Adel
Tags
Summary
This lecture covers various aspects of mobile application development using Dart, including control flow statements (if-else, switch-case), looping constructs (for, for-in), and loop control statements. The lecture notes provide code examples to illustrate different programming techniques.
Full Transcript
Mobile Application Development Lec. 3 Dr. Samah Adel Control Flow in Dart Control Flow in Programming is refers to the order in which set of instructions or statements that are executed or evaluated. It provides flexibility in Decision making and makes code more user friendly....
Mobile Application Development Lec. 3 Dr. Samah Adel Control Flow in Dart Control Flow in Programming is refers to the order in which set of instructions or statements that are executed or evaluated. It provides flexibility in Decision making and makes code more user friendly. Dart – If-Else Statements ◦ Dart – Switch Case Statements ◦ Dart – Loops ◦ Dart – Loop Control Statements ◦ Labels in Dart ◦ If-Else Statements There are four ways to achieve this: 1. if Statement 2. if-else Statement 3. else-if Ladder 4. Nested if Statement 1. if Statement 2. if-else Statement 3. else-if Ladder 4. Nested if Statement Example Try code of if-else with Operator Switch Case in Dart In Dart, switch-case statements are a simplified version of the nested if-else statements. Its approach is the same as that in Java. Syntax Rules to follow in switch case: 1.There can be any number of cases. But values should not be repeated. 2.The case statements can include only constants. It should not be a variable or an expression. 3.There should be a flow control i.e break within cases. If it is omitted than it will show error. 4.The default case is optional. 5.Nested switch is also there thus you can have switch inside switch. Example 1: Normal switch-case statement Example 2: Nested switch-case statement Dart – Loops A looping statement in Dart or any other programming language is used to repeat a particular set of commands until certain conditions are not completed. There are different ways to do so. They are: ◦ for loop ◦ for… in loop ◦ for each loop ◦ while loop ◦ do-while loop 1. for loop For loop in Dart is similar to that in Java and also the flow of execution is the same as that in Java. Syntax: 2. for…in loop For…in loop in Dart takes an expression or object as an iterator. It is similar to that in Java and its execution flow is also the same as that in Java. Syntax: 3. for each … loop The for-each loop iterates over all elements in some container/collectible and passes the elements to some specific function. Syntax: while loop The body of the loop will run until and unless the condition is true. Syntax do..while loop The body of the loop will be executed first and then the condition is tested. Loop Control Statements (Break and Continue) Example 1: Using break inside while loop Example 2: Using break inside do..while loop Example 3: Using break inside for loop Continue Statement: While the break is used to end the flow of control, continue on the other hand is used to continue the flow of control. When a continue statement is encountered in a loop it doesn’t terminate the loop but rather jump the flow to next iteration. Example 1: Using continue inside while loop Example 2: Using continue inside do..while loop Example 3: Using continue inside for loop