control structures in structured programming, we use three basic control structures: –sequence...
TRANSCRIPT
![Page 1: Control Structures In structured programming, we use three basic control structures: –Sequence –Selection –Repetition So far, we have worked with sequential](https://reader036.vdocument.in/reader036/viewer/2022082612/56649f205503460f94c384f3/html5/thumbnails/1.jpg)
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
![Page 2: Control Structures In structured programming, we use three basic control structures: –Sequence –Selection –Repetition So far, we have worked with sequential](https://reader036.vdocument.in/reader036/viewer/2022082612/56649f205503460f94c384f3/html5/thumbnails/2.jpg)
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 “Yes” Print “No”Print “No”
True False
IF 1 is greater than 2 THEN Print “Yes”ELSE Print “No”ENDIF
![Page 3: Control Structures In structured programming, we use three basic control structures: –Sequence –Selection –Repetition So far, we have worked with sequential](https://reader036.vdocument.in/reader036/viewer/2022082612/56649f205503460f94c384f3/html5/thumbnails/3.jpg)
Relational Operators
• Used to test the relationship between two expressions or two variables
• Condition evaluates as .FALSE.
.TRUE.
![Page 4: Control Structures In structured programming, we use three basic control structures: –Sequence –Selection –Repetition So far, we have worked with sequential](https://reader036.vdocument.in/reader036/viewer/2022082612/56649f205503460f94c384f3/html5/thumbnails/4.jpg)
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
![Page 5: Control Structures In structured programming, we use three basic control structures: –Sequence –Selection –Repetition So far, we have worked with sequential](https://reader036.vdocument.in/reader036/viewer/2022082612/56649f205503460f94c384f3/html5/thumbnails/5.jpg)
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
![Page 6: Control Structures In structured programming, we use three basic control structures: –Sequence –Selection –Repetition So far, we have worked with sequential](https://reader036.vdocument.in/reader036/viewer/2022082612/56649f205503460f94c384f3/html5/thumbnails/6.jpg)
Examples
x = 500, y = 300
x= =y
x > 100
y >=250
x /= 500
((x + y) > 700)
((x / 2) .LT. 99)
![Page 7: Control Structures In structured programming, we use three basic control structures: –Sequence –Selection –Repetition So far, we have worked with sequential](https://reader036.vdocument.in/reader036/viewer/2022082612/56649f205503460f94c384f3/html5/thumbnails/7.jpg)
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
![Page 8: Control Structures In structured programming, we use three basic control structures: –Sequence –Selection –Repetition So far, we have worked with sequential](https://reader036.vdocument.in/reader036/viewer/2022082612/56649f205503460f94c384f3/html5/thumbnails/8.jpg)
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.
Onlyevaluates as false if both false
(.NOT. (x >= 7)) reverses the value of expression toits immediate right. same as if (x < 7) then
![Page 9: Control Structures In structured programming, we use three basic control structures: –Sequence –Selection –Repetition So far, we have worked with sequential](https://reader036.vdocument.in/reader036/viewer/2022082612/56649f205503460f94c384f3/html5/thumbnails/9.jpg)
Order of Precedence( ) Parentheses highest** Exponentiation *, / Multiplication,Division+, - Addition, Subtraction
< <= > >= Greater than, less than, …or equal= = /= Equal, not equal.AND. And.OR. Or= Assignment statement lowest
Rule: Use parentheses to make evaluation order clear
![Page 10: Control Structures In structured programming, we use three basic control structures: –Sequence –Selection –Repetition So far, we have worked with sequential](https://reader036.vdocument.in/reader036/viewer/2022082612/56649f205503460f94c384f3/html5/thumbnails/10.jpg)
Conditions Practice
• 1. “A” < “F”
“cat” < “can”
“June” > “July”
“cat_ _ _” < “cattle”
“c” = = “C”
![Page 11: Control Structures In structured programming, we use three basic control structures: –Sequence –Selection –Repetition So far, we have worked with sequential](https://reader036.vdocument.in/reader036/viewer/2022082612/56649f205503460f94c384f3/html5/thumbnails/11.jpg)
Conditions Practice
• 1. Given a = 12, b = 6, c = 8true or false? ((a < b) .AND. (b /= c) (.NOT.(a < b) .AND. .NOT.(b > 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))