Wk03 PROG8240 LecNotes
Wk03 PROG8240 LecNotes
Structured Programming
Today’s Highlights
• Data Hierarchy
• Variables and Constants
• Parentheses in Operator Precedence
• Relational and Logical Operators
• Program Development and Programming Tools
• Control Structures for Decision Making
• If…Then…Else blocks
• Input Validation
Structured Programming 7
Data Hierarchy
• Data items processed by
computers form a data
hierarchy that becomes
larger and more complex in
structure as we progress
from the simplest data items
(called “bits”) to richer data
items, such as characters,
fields, and so on.
Structured Programming 8
1
PROG8240 Lecture notes – week #03
Structured Programming
Structured Programming 10
2
PROG8240 Lecture notes – week #03
Structured Programming
• A – Z: 65 – 90; a – z: 97 - 122
Structured Programming 11
Structured Programming 12
3
PROG8240 Lecture notes – week #03
Structured Programming
Structured Programming 13
• Initialization
• To specify an initial string value
Structured Programming 14
4
PROG8240 Lecture notes – week #03
Structured Programming
5
PROG8240 Lecture notes – week #03
Structured Programming
Structured Programming 17
Structured Programming 18
6
PROG8240 Lecture notes – week #03
Structured Programming
Structured Programming 19
Logical Operators
• An expression that evaluates to either True or False is
said to have Boolean data type.
• Used with Boolean-valued expressions:
• And – will yield a True if and only if both expressions are
True.
• Or – will yield a True if one of both expressions is True.
• Not – makes a False expression True and vice versa.
• Truth Tables of And / Or / Not:
AND OR NOT
A B X A B X A X
0 0 0 0 0
0 1 0 1 1
1 0 1 0
1 1 1 1
Structured Programming 20
7
PROG8240 Lecture notes – week #03
Structured Programming
Structured Programming 21
Control Structures
• Three most important structures
that control the program flow:
• Sequential Structure: the
statements are executed
sequentially.
Structured Programming 22
8
PROG8240 Lecture notes – week #03
Structured Programming
Structured Programming 23
Structured Programming 24
9
PROG8240 Lecture notes – week #03
Structured Programming
If condition Then
action 1
End If Regardless of whether
10
PROG8240 Lecture notes – week #03
Structured Programming
If condition Then
action 1
Else
action 2
End If
Structured Programming 27
11
PROG8240 Lecture notes – week #03
Structured Programming
If condition 1 Then
action 1
ElseIf condition 2 Then
action 2
ElseIf condition 3 Then
action 3
Else
action 4
End If
Structured Programming 29
Input Validation
• The statement
If (IsNumeric(txtBox.Text) = True) Then
is commonly used to validate that input is
numeric. It can be condensed to
If IsNumeric(txtBox.Text) Then
Structured Programming 30
12