Chapter 4a Relational Operators and Conditional Statements - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

Chapter 4a Relational Operators and Conditional Statements

Description:

Decision structures in VB are very similar to subjunctive statements in English. ... English outline that is easy to translate into real code. Example ... – PowerPoint PPT presentation

Number of Views:43
Avg rating:3.0/5.0
Slides: 10
Provided by: carlo316
Category:

less

Transcript and Presenter's Notes

Title: Chapter 4a Relational Operators and Conditional Statements


1
Chapter 4a Relational Operators and
Conditional Statements
4a
CI 9008 George Zolla
IS 2020
. Gary Porter
grporter_at_
nps
.navy.mil
Naval Postgraduate School
Monterey, CA
2
(No Transcript)
3
IfThen
  • If weaponsRange lt firingRange Then
  • round 1
  • fire(round, firingRange, weaponsRange)
  • End If
  • Does not consider an else condition.
  • Useful for simple comparisons

Withing Range?
F
C1 ?
T
Fire
S1 ..
4
Decision Structures
  • Decision structures in VB are very similar to
    subjunctive statements in English. For instance,
    consider the following subjunctive statement
  • If my average golf score is 10 or more strokes
    less than yours, then I will give you a 5 stroke
    handicap on our next game.
  • This statement can be directly translated into VB
    code as shown in the following code fragment
  • difference yourAverageScore - myAverageScore
  • If difference gt 10 Then
  • handicap 5
  • End If

5
IfThenElse
  • Handles situations with 2 outcomes
  • If condition Then
  • statementblock 1
  • Else
  • statementblock 2
  • End If

6
Components of IfThenElse statement
l l l l l l l l
End If
7
If-Then-Else Blocks
  • If weaponsRange lt firingRange Then
  • rounds 1
  • fire(rounds, weaponsRange, firingRange)
  • Else
  • speed flankSpeed
  • End If

8
PseudoCode
  • English outline that is easy to translate into
    real code.
  • Example
  • If users guess random number then
  • beep
  • else
  • display messages
  • end if

9
Programming Style
  • Different If-Then styles are possible.
  • Notice how indentation improves the readability
    of the code.
  • Keeping the If and End If keywords aligned is a
    common practice that is used to improve code
    readability.
Write a Comment
User Comments (0)
About PowerShow.com