Download presentation
Presentation is loading. Please wait.
Published byมะลิ เก่งงาน Modified over 5 years ago
1
Lesson 3. Controlling program flow. Loops. Methods. Arrays.
Programming in C# Lesson 3. Controlling program flow. Loops. Methods. Arrays.
2
Three types of program flow
Straight line Chosen depending on a given condition Repeated according to a given condition
3
Making decisions
4
Making decisions in UML diagram
5
Two main constructions to control program flow
IF/ELSE SWITCH
6
IF/ELSE construction if (condition) statement or block we do if the condition is true else statement or block we do if the condition is false
7
Conditions and Relational Operators
== > < <= >= != ! Only two types of values: true or false
8
Combining Logical Operators
&& ||
9
Combining Logical Operators sample:
10
Combining Logical Operators inversed sample:
11
SWITCH construction switch (value) { } case ‘option 1’:
statement or block we do if value equals ‘option 1’ break; case ‘option 2’: statement or block we do if value equals ‘option 2’ case ‘option 3’: statement or block we do if value equals ‘option 3’ default: statement or block we do in all other cases }
12
Loops
13
Loops in UML diagram
14
Four main types of loops
DO-WHILE WHILE FOR FOREACH
15
DO-WHILE Loop do statement or block while (condition);
16
DO-WHILE Loop Sample
17
WHILE Loop while (condition) statement or block
18
WHILE Loop Sample
19
FOR Loop for (setup; finish test; update) things we want to do a given number of times
20
FOR Loop Sample
21
Breaking Out of Loops break continue
22
Methods Reusing a piece of code
Break down a large task into a number of smaller ones
23
Simple method sample
24
Method Parameters
25
Method Parameters
26
Method Signature Type of Parameters Number of Parameters Return Type
27
Parameter Passing By Value
28
Parameter Passing By Reference
29
Passing Parameters as “out” Reference
30
What else should we know about method parameters?
Default parameters Variable number of parameters Method overload
31
Arrays
32
Array declaration
33
Array in Memory
34
Array Elements
35
Array Elements Initialization
36
Managing Array Sizes
37
Two Dimensional Arrays
38
Two Dimensional Array Declaration
39
Arrays and Lookup Tables
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.