SlideShare a Scribd company logo
Basic Scientific Programming
Selective Execution
Selective Execution
Selective execution gives the programmer the
ability to execute a part of the code if a
condition is met. Else that part of code is not
executed.
The selection is based on a logical
expression.
Logical Expressions






Logical expressions may be simple or
compound.

Simple logical expression
expression1 logical operator expression2
Compound logical expression
formed by combining simple logical
expressions by using the following logical
operators: NOT, AND, OR, EQV, NEQV.
Relational Operators
Symbol

Meaning

Example

<

Is less than

x<y

>

Is greater than

x>y

==

Is equal to

x == y

<=

Is less than or equal to

x <= y

>=

Is greater than or equal to

x >= y

/=

Is not equal to

x /= y


The result of a logical operation is either
“true” or “false”.
5>4
9<6
3>3

true.
false.
false.
Characters & Relational Operators




Numeric codes are used to establish an
ordering for the character set.
ASCII & EBCDIC “Refer to App. A”
“CAT” < “DOG” true C precedes D in the table.
“June” < “July” false l precedes n in the table.
“June” < “june” true J precedes j in the table.
Two strings are compared as though blanks are appended to the
shorter string.
“cat” < “cattle” true a blank space precedes t in the table.


Logical expressions formed by comparing real values
with == are often evaluated as false, why?
because real values are stored with some error.
Real:: value
value = 10
if ( (1/value) == 0.1) then
do something
end if
In this example (1/value) might not result in 0.1 due to
storage limitations, it might be 0.998 or 0.10001
Declaring logical variables
There are two logical constants in Fortran
.TRUE. .FALSE.
Declaration:
LOGICAL :: VARIABLE_LIST
Reading logical variables is similar to reading other
data types.
Ex. Logical :: A,B,C
Read *, A,B,C
Input : .T. , F, .False “any form is valid input”
Logical Operators






.NOT.
.AND.
.OR.
.EQV.
.NEQV.
A
F
T

.NOT. A
T
F
AND/ OR
AND
A
F

B
F

F

T

T
T

OR

A .AND. B
F

A
F

B
F

A .OR.B
F

F

F

T

T

F

F

T

F

T

T

T

T

T

T
EQV/NEQV
EQV
A
F

B
F

F

T

T
T

NEQV

A .EQV. B
T

A
F

B A .NEQV. B
F
F

F

F

T

T

F

F

T

F

T

T

T

T

T

F
Priorities


In logical expression containing several of
these operators, the operations are
performed in the following order
.NOT.  .AND.  .OR.  .EQV. (or .NEQV.)

Parenthesis may be used to indicate the subexpressions that must be evaluated first.
Ex:

A .AND. B .OR. .NOT. C
A .AND. (B .OR. .NOT. C)
The general case
The most general case is to have logical expressions
containing arithmetic, relational and logical operators.
The operations are performed in the following order:
1. Arithmetic operations
2. Relational operations
3. Logical operations
Ex: (((b**2 – 4* a* c) >=5) .and. c+2 <6)
Flowchart Symbols
Begin or End

Input or Output

Assignment

Point of Selection

Multiway Selection

Flow Lines join
IF Construct
IF (Logical Expression) then
Statement-Sequence
End IF
Selection is made between
either executing the sequence
of statements or bypassing it.

if

Stat. seq
General form of IF Construct
IF (Logical Expression) then
Statement-Sequence1
ELSE
Statement-Sequence2
End IF
Selection is made between
either executing sequence1
or sequence2.

if

Stat. seq1

Stat. seq2
Nested IF


The sequence of statements in an IF construct may
itself contain other IF constructs.
Ex: if(X<=0) then
value = -X
else
if (X<1.0)then
value = X**2
else
value=1.0
end if
end if
IF

ELSE IF Construct

IF(logical expression1) then
statement sequence 1
ELSE IF (logical expression2) then
statement sequence 2
ELSE IF (logical expression3) then
statement sequence 3
.
.
.
ELSE
statement sequence n
END IF
IF




ELSE IF Construct
This structure is used in cases involving
multiple alternatives.
Only one of the statement sequences will be
executed, the others will be skipped.

More Related Content

PPT
Ap Power Point Chpt3 B
PPT
Shubhrat operator &amp; expression
DOC
Week2 dq4
PPTX
Parametricity
PPT
Ap Power Point Chpt3
PDF
JetBrains MPS: Editor Aspect
Ap Power Point Chpt3 B
Shubhrat operator &amp; expression
Week2 dq4
Parametricity
Ap Power Point Chpt3
JetBrains MPS: Editor Aspect

What's hot (20)

PPTX
Module 3 : using value type variables
PDF
JetBrains MPS: Typesystem Aspect
PPTX
Software Engineering - Module 3: Lesson7
PPT
Frequently asked questions in c
DOC
PDF
Programming in c by pkv
PPTX
Types of Parser
PPTX
Type conversion, precedence, associativity in c programming
PPTX
Operators in java
PPTX
Type Conversion, Precedence and Associativity
PPT
Problem Solving Techniques
PPT
Frequently asked questions in c
PPT
Getting started with c++
PDF
C interview questions
PDF
C programming | Class 8 | III Term
PDF
Operators in java
PDF
Java basic operators
PPTX
Attribute grammer
PPTX
Top down parsing
Module 3 : using value type variables
JetBrains MPS: Typesystem Aspect
Software Engineering - Module 3: Lesson7
Frequently asked questions in c
Programming in c by pkv
Types of Parser
Type conversion, precedence, associativity in c programming
Operators in java
Type Conversion, Precedence and Associativity
Problem Solving Techniques
Frequently asked questions in c
Getting started with c++
C interview questions
C programming | Class 8 | III Term
Operators in java
Java basic operators
Attribute grammer
Top down parsing
Ad

Similar to 8 if (20)

PPTX
OCA Java SE 8 Exam Chapter 2 Operators & Statements
PPTX
Lewis_Cocking_AP_Decision_Making_For_Coding
PPTX
Introduction to Java
PPTX
ChapterTwoandThreefnfgncvdjhgjshgjdlahgjlhglj.pptx
PPT
slides03.ppt
PPTX
MODULE_2_Operators.pptx
PPTX
Java Programming
PPTX
Lecture-02-JAVA, data type, token, variables.pptx
PPTX
Python.pptx
PPT
Types of c operators ppt
PPT
Control structures i
PPTX
Python Week 1.pptx
PPTX
UNIT 2 programming in java_operators.pptx
PDF
Pythonintro
DOCX
Programming Fundamentals lecture 7
PDF
07 top-down-parsing
PPT
C operators
PPTX
INTRODUCTION TO C PROGRAMMING - PART 2
PPT
Cprogrammingoperator
PPTX
Programming in C
OCA Java SE 8 Exam Chapter 2 Operators & Statements
Lewis_Cocking_AP_Decision_Making_For_Coding
Introduction to Java
ChapterTwoandThreefnfgncvdjhgjshgjdlahgjlhglj.pptx
slides03.ppt
MODULE_2_Operators.pptx
Java Programming
Lecture-02-JAVA, data type, token, variables.pptx
Python.pptx
Types of c operators ppt
Control structures i
Python Week 1.pptx
UNIT 2 programming in java_operators.pptx
Pythonintro
Programming Fundamentals lecture 7
07 top-down-parsing
C operators
INTRODUCTION TO C PROGRAMMING - PART 2
Cprogrammingoperator
Programming in C
Ad

More from fyjordan9 (17)

PPT
17recursion
PPT
16 subroutine
PPT
15 functions
PPT
14 arrays
PPT
13 arrays
PPT
12 doloops
PPT
11 doloops
PPT
10 examples for if statement
PPT
9 case
PPT
7 files
PPT
6 read write
PPT
5 format
PPT
4 design
PPT
3 in out
PPT
2 int real
PPT
1 arithmetic
PDF
PHYS303
17recursion
16 subroutine
15 functions
14 arrays
13 arrays
12 doloops
11 doloops
10 examples for if statement
9 case
7 files
6 read write
5 format
4 design
3 in out
2 int real
1 arithmetic
PHYS303

Recently uploaded (20)

PPTX
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PPTX
Cell Structure & Organelles in detailed.
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Yogi Goddess Pres Conference Studio Updates
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
01-Introduction-to-Information-Management.pdf
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
A systematic review of self-coping strategies used by university students to ...
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
Paper A Mock Exam 9_ Attempt review.pdf.
Cell Structure & Organelles in detailed.
Supply Chain Operations Speaking Notes -ICLT Program
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Yogi Goddess Pres Conference Studio Updates
STATICS OF THE RIGID BODIES Hibbelers.pdf
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Weekly quiz Compilation Jan -July 25.pdf
01-Introduction-to-Information-Management.pdf
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Chinmaya Tiranga quiz Grand Finale.pdf
Final Presentation General Medicine 03-08-2024.pptx
Module 4: Burden of Disease Tutorial Slides S2 2025
Practical Manual AGRO-233 Principles and Practices of Natural Farming

8 if

  • 2. Selective Execution Selective execution gives the programmer the ability to execute a part of the code if a condition is met. Else that part of code is not executed. The selection is based on a logical expression.
  • 3. Logical Expressions    Logical expressions may be simple or compound. Simple logical expression expression1 logical operator expression2 Compound logical expression formed by combining simple logical expressions by using the following logical operators: NOT, AND, OR, EQV, NEQV.
  • 4. Relational Operators Symbol Meaning Example < Is less than x<y > Is greater than x>y == Is equal to x == y <= Is less than or equal to x <= y >= Is greater than or equal to x >= y /= Is not equal to x /= y
  • 5.  The result of a logical operation is either “true” or “false”. 5>4 9<6 3>3 true. false. false.
  • 6. Characters & Relational Operators   Numeric codes are used to establish an ordering for the character set. ASCII & EBCDIC “Refer to App. A” “CAT” < “DOG” true C precedes D in the table. “June” < “July” false l precedes n in the table. “June” < “june” true J precedes j in the table. Two strings are compared as though blanks are appended to the shorter string. “cat” < “cattle” true a blank space precedes t in the table.
  • 7.  Logical expressions formed by comparing real values with == are often evaluated as false, why? because real values are stored with some error. Real:: value value = 10 if ( (1/value) == 0.1) then do something end if In this example (1/value) might not result in 0.1 due to storage limitations, it might be 0.998 or 0.10001
  • 8. Declaring logical variables There are two logical constants in Fortran .TRUE. .FALSE. Declaration: LOGICAL :: VARIABLE_LIST Reading logical variables is similar to reading other data types. Ex. Logical :: A,B,C Read *, A,B,C Input : .T. , F, .False “any form is valid input”
  • 10. AND/ OR AND A F B F F T T T OR A .AND. B F A F B F A .OR.B F F F T T F F T F T T T T T T
  • 11. EQV/NEQV EQV A F B F F T T T NEQV A .EQV. B T A F B A .NEQV. B F F F F T T F F T F T T T T T F
  • 12. Priorities  In logical expression containing several of these operators, the operations are performed in the following order .NOT.  .AND.  .OR.  .EQV. (or .NEQV.) Parenthesis may be used to indicate the subexpressions that must be evaluated first. Ex: A .AND. B .OR. .NOT. C A .AND. (B .OR. .NOT. C)
  • 13. The general case The most general case is to have logical expressions containing arithmetic, relational and logical operators. The operations are performed in the following order: 1. Arithmetic operations 2. Relational operations 3. Logical operations Ex: (((b**2 – 4* a* c) >=5) .and. c+2 <6)
  • 14. Flowchart Symbols Begin or End Input or Output Assignment Point of Selection Multiway Selection Flow Lines join
  • 15. IF Construct IF (Logical Expression) then Statement-Sequence End IF Selection is made between either executing the sequence of statements or bypassing it. if Stat. seq
  • 16. General form of IF Construct IF (Logical Expression) then Statement-Sequence1 ELSE Statement-Sequence2 End IF Selection is made between either executing sequence1 or sequence2. if Stat. seq1 Stat. seq2
  • 17. Nested IF  The sequence of statements in an IF construct may itself contain other IF constructs. Ex: if(X<=0) then value = -X else if (X<1.0)then value = X**2 else value=1.0 end if end if
  • 18. IF ELSE IF Construct IF(logical expression1) then statement sequence 1 ELSE IF (logical expression2) then statement sequence 2 ELSE IF (logical expression3) then statement sequence 3 . . . ELSE statement sequence n END IF
  • 19. IF   ELSE IF Construct This structure is used in cases involving multiple alternatives. Only one of the statement sequences will be executed, the others will be skipped.

Editor's Notes

  • #14: always use parenthesis to control the order of execution.