Title: Discussion
1Discussion 4 Loops and Trees
2Three Programming Constructs
3Programming Constructs (continued)
- Do instructions in sequence
- Fred 27
- Jane 16
- Fred Jane - Fred
- Jane Fred/2
4Programming Constructs (continued)
- Choose task A (True) or task B (False)
- IF (Score gt 93)
- Grade 'A'
-
- ELSE
- Grade 'E'
5Programming Constructs (continued)
- Repeatedly execute tasks
- FOR (init limit increment)
- FOR (i0 ilt10 i)
- Answer Answeri
6Scope
- Scope binds a block of instructions together
- Braces define scope
FOR (i1 ilt8 i)
IF (i lt 3)
A i i B i i
4
- What is the final value of B?
7Scope
- Scope binds a block of instructions together
- Braces define scope
FOR (i1 ilt8 i)
IF (i lt 3) B i i
A i i
14
- What is the final value of B?
8Scope
- Scope binds a block of instructions together
- Braces define scope
FOR (i1 ilt8 i) B i i
IF (i lt 5)
A i i
16
- What is the final value of B?
9Loops and Trees
10Review Arrays
What if AA had 10,000 items?
i 0 AAi0 i1 AAi0 i2 AAi0 i3 A
Ai0 i4 AAi0
i
?
0
1
2
3
4
AA
?
0
0
?
1
0
2
?
0
?
3
0
?
4
0
112D Arrays (images)
What if the image was 1024 x 1024?
Img
X1 Y1 P ImgX,Y ImgX,Y
0 Y2 ImgX,Y128 X2 ImgX,Y255
1
2
0 Black 128 Gray 255 White
2
1
255
12Strings
i
0
1
2
i 0 NameiNamei 32 i
1 NameiNamei 32 i 2 NameiNamei
32
Name
66 (B)
79 (O)
34 (")
13FOR Loop
What if Name had 10,000 characters?
i
0
3
1
2
FOR (i0 iltlength(Name) ii1) C
Namei IF (Cgt'a' Clt'z')
Namei Namei 32
C
98
111
66
Name
66 (B)
79 (O)
14Records (a collection of named things)
Student
3.6
West Cobblestone
Student.GPA 3.6 Student.Address West
Cobblestone
15An Array of Students
Students
Betty Rubble
F
16Trees
BYU
BioAg
Business
PhysSci
Stat
Zoology
Acnt
Market
CS
Math
Botany
CS100
CS235
CS142
17BYU.PhysSci.CS.CS1000.GPA2.9
BYU
BioAg
Business
PhysSci
Stat
Zoology
Acnt
Market
CS
Math
Botany
CS100
CS235
CS142
2.9
18Review of Information
- Binary
- Numbers - Integer, Floating Point
- Characters
- Arrays, Strings
- Records (named things)
- Trees
19Review of programs
- Expressions
- Variables
- Assignment
- Sequence
- If
- For loop