Intro to Computer Programming Lesson 3 - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

Intro to Computer Programming Lesson 3

Description:

... have the code to calculate the hypotenuse, now we'll add the comparison inside the loop. ... Hypotenuse = '; LRG. 330 PRINT 'Smallest Hypotenuse = '; SML ... – PowerPoint PPT presentation

Number of Views:49
Avg rating:3.0/5.0
Slides: 9
Provided by: ekel9
Category:

less

Transcript and Presenter's Notes

Title: Intro to Computer Programming Lesson 3


1
Intro 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 ,
2
READ - 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
3
Intro 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.
4
Intro 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
5
Intro 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.
6
Intro 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
7
Intro 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
8
Concept 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.
Write a Comment
User Comments (0)
About PowerShow.com