Professional Documents
Culture Documents
Lect04 Introducing Algorithms, Pseudocode, and Program Control
Lect04 Introducing Algorithms, Pseudocode, and Program Control
T U T O R I A L
Wage Calculator
7
Application
Introducing Algorithms,
Pseudocode and
Program Control
2009 Pearson Education, Inc. All rights reserved.
2
Outline
Objectives
Introduction
■ Structured programming
– A technique for organizing program control that
helps you develop applications that are clear and
easier to debug and modify.
– Applicable to most high-level languages, including
Visual Basic.
7.2 Algorithms
7.3 Pseudocode
■ Sequential execution
– Normally, statements in an application are executed one
after another in the order in which they are written.
■ transfer of control
– Occurs when an executed statement does not directly
follow the previously executed statement in the written
application.
■ All programs can be written in terms of only
three control structures:
– the sequence structure,
– the selection structure and
– the repetition structure.
2009 Pearson Education, Inc. All rights reserved.
18
Selection Structures
■ A condition is an expression with a true or
false value that is used to make a decision.
■ Conditions are evaluated to determine whether
their value is true or false.
■ These values are of data type Boolean
– Specified in Visual Basic code by using the keywords
True and False.
■ Refer to a condition as a Boolean expression.
Repetition Structures
■ Visual Basic provides seven types of repetition
structures for performing a statement or group
of statements repeatedly:
– While...End While
– Do While...Loop
– Do Until...Loop
– Do...Loop While
– Do...Loop Until
– For...Next
– For Each...Next
Keywords
■ The words If, Then, Else, End, Select, Case,
While, Do, Until, Loop, For, Next and Each
are all Visual Basic keywords—Appendix E
includes a complete list of Visual Basic keywords.
Equality operators
= = x = y X is equal to y
Syntax
If condition Then
[ statements ]
End If
Syntax
If condition Then
[ statements ]
Else
[ statements ]
End If
Else
Gross earnings equals 40 times hourly
wage plus hours above 40 times wage and
a half
Display gross earnings earningsResultLabel
Variable declarations
Constant declaration
Variable assignment
Error-Prevention Tip
To reduce errors, the IDE sometimes adds keywords for
you. One example is the adding of the keywords
End...If when an If...Then or an
If...Then...Else statement is created. This eliminates
the possibility that such keywords will be forgotten or
misspelled.
Displaying output
Addition assignment
operator shortens
statement
Figure 7.21 | Using the Format method to display the result as currency.
2009 Pearson Education, Inc. All rights reserved.
73
Complex expression
Boolean expression
Invalid expression