Title: Intro to Computer Programming Lesson 3
1Intro to Computer Programming Lesson 3
Review Controlled Loop executes a known number
of times. FOR ltvariablegt ltstart valuegt TO ltend
valuegt STEP ltvaluegt FOR J 2 to 30 STEP 3
Deliminators A term used to identify those
symbols used to separate information.
Colon Semicolon Comma ,
2READ - DATA
- If we want to do multiple calculations, we need
a method of changing the value without having to
stop and rewrite our program.
We use a command set of words READ DATA (you
cannot have a READ command without DATA) READ
NME, PHONE, ZIPCODE, STULOAD DATA Ed
Kellner, 9740909, 33620, 170
3Intro to Computer Programming Lesson 3
LOGICAL COMPARISON
Compare the relationship of two items
(variables), using the TRICOTOMY
Using variables A and B A lt B A B A gt B Only
one is true, the other two are false.
Corollary If one of the TRICOTOMY is FALSE, then
one of the other two must be TRUE.
4Intro to Computer Programming Lesson 3
Logical Command IF Command Set
IF/THEN/ELSE (ELSE is optional) IF (
ltcomparisongt) THEN ltaction TRUEgt ELSE ltaction
FALSEgt
Example IF (A gt B) THEN PRINT A is Greater
ELSE PRINT B is Greater IF (A lt 0) THEN PRINT
A is Negative ELSE PRINT A is positive
5Intro to Computer Programming Lesson 3
Comparisons for Largest and Smallest
Initialize variables for the largest value and
the smallest value For this example, let us use
LRG and SML
LRG 0 SML 9999 Need to have an initial value,
such that it will be replaced on the first
comparison.
6Intro to Computer Programming Lesson 3
200 LRG 0 210 SML 999 220 FOR J 1 TO
4 230 READ A, B 240 A2 A 2 250 B2 B
2 260 C2 A2 B2 270 C C2 (1/2) 280
PRINT A, B, C
290 IF (C lt SML) THEN SML C 300 IF (C gt LRG)
THEN LRG C
310 NEXT J
320 PRINT Largest LRG, Smallest SML
7Intro to Computer Programming Lesson 3
Consider that we want to find the largest and
smallest hypotenuses, from a series that we
calculate. We already have the code to calculate
the hypotenuse, now well add the comparison
inside the loop.
290 IF (C lt SML) THEN SML C 300 IF (C gt LRG)
THEN LRG C
320 PRINT Largest Hypotenuse LRG 330
PRINT Smallest Hypotenuse SML
8Concept Question
- Scale 5 very well to 1 no clue
- Q-1. Rate how well you feel you understand the
concept of Logical Comparison - Q-2. Rate how well you feel you understand the
concept of initializing a value, and why you need
to initialize the value.