Presentation is loading. Please wait.

Presentation is loading. Please wait.

Control Structures In structured programming, we use three basic control structures: –Sequence –Selection –Repetition So far, we have worked with sequential.

Similar presentations


Presentation on theme: "Control Structures In structured programming, we use three basic control structures: –Sequence –Selection –Repetition So far, we have worked with sequential."— Presentation transcript:

1 Control Structures In structured programming, we use three basic control structures: –Sequence –Selection –Repetition So far, we have worked with sequential algorithms, where each instruction is executed once, immediately after the one above it

2 Selection We use selection to handle making choices A condition that is evaluated to be either true or false determines the next action Is a > b? Print “Yes” Print “No” TrueFalse IF 1 is greater than 2 THEN Print “Yes” ELSE Print “No” ENDIF

3 Relational Operators Used to test the relationship between two expressions or two variables Condition evaluates as.FALSE..TRUE.

4 FORTRAN’s Relational Operators = =Equal uses two equal signs >Greater than <Less than >=Greater than or equal to <=Less than or equal to /=Not equal

5 FORTRAN’s Relational Operators = = or.EQ.Equal uses two equal signs >or.GT.Greater than <or.LT.Less than >= or.GE.Greater than or equal to <= or.LE.Less than or equal to /= or.NE.Not equal

6 Examples x = 500, y = 300 x= =y x > 100 y >=250 x /= 500 ((x + y) > 700) ((x / 2).LT. 99)

7 Compound Logical Expressions Used to combine or negate expressions containing logical operators. –used with compound conditions.AND. And.OR.Or.NOT.Not.EQV.Equivalence.NEQV.Nonequivalence

8 Logical Operators ((x == 5).AND. (y != 10))both conditions must be true for statement to evaluate as true ((x == 7).OR. (y > 10))either condition can be true for statement to evaluate is true. Only evaluates as false if both false (.NOT. (x >= 7))reverses the value of expression to its immediate right. same as if (x < 7) then

9 Order of Precedence ( ) Parentheseshighest **Exponentiation *, /Multiplication,Division +, -Addition, Subtraction >= Greater than, less than, …or equal = = /=Equal, not equal.AND.And.OR.Or =Assignment statementlowest Rule: Use parentheses to make evaluation order clear

10 Conditions Practice 1.“A” < “F” “cat” < “can” “June” > “July” “cat_ _ _” < “cattle” “c” = = “C”

11 Conditions Practice 1. Given a = 12, b = 6, c = 8 true or false? ((a < b).AND. (b /= c) (.NOT.(a c)) ((a > b).AND.(a > c).OR.(b > c)) 2. What would the values of a, b, and c need to be for this statement to be true? (use 1,2,3) ((a >c.OR. b > c).AND. (a < b))


Download ppt "Control Structures In structured programming, we use three basic control structures: –Sequence –Selection –Repetition So far, we have worked with sequential."

Similar presentations


Ads by Google