lmayer@elgin.edu

Week 8

Chapter 6 - IF Statements

Structured Programming uses 3 Basic Control Structures:
1. Sequence - actions executed in the order that they appear
2. IF-THEN-ELSE - choice between two alternatives (or CASE for more alternatives)
3.DO-LOOP or repetition (FOR) - repeated execution of a loop

No GOTOs!!!!!

IF condition THEN
   Clause
ELSE
   Clause
END IF

Single Line IFs need no END IF
IF condition THEN statement ELSE statement

Comparing strings – based on numerical and alphabetical order, case sensitive:
number < uppercase < lowercase

ALU returns –1 if true, 0 if false

Nested IFs:

SELECT CASE  test expression
  
CASE IS match expression
         Statement(s)
  
CASE IS match expression
         Statement(s)
  
CASE IS match expression
         Statement(s)\
  
CASE ELSE
         Statement(s)
END SELECT

Accumulators:
Counters:  count number of times something happens
incremented by one each event (action or pass through loop)
Running Total: used to sum the values a variable is assigned

Logical Operators: (truth table page 182)

  • NOT
  • AND both must be true
  • OR  either one or both true
  • XOR one, but not other true
  • EQV   both true or both false
  • IMP   (implication)

Order of precedence:
Parenthesis, Arithmetic operators, relational (< , = , >), NOT, AND, OR or XOR, EQV, IMP

Data Validation: (example: SS# is nine digits)

    • reasonableness check age is positive
    • range check  input is within valid range
    • value or code check  input is a valid value
    • digit check  serial numbers begin with specific digit

When errors are detected, use the BEEP statement to alert the user