SlideShare a Scribd company logo
Understanding Structure
Understanding the Three Basic Structures
In the mid-1960s, mathematicians proved that any program, no matter how
complicated, can be constructed using one or more of only three structures.
A structure is a basic unit of programming logic; each structure is one of the
following:
• Sequence
• Selection
• Loop
With these three structures alone, you can diagram any task, from doubling
a number to performing brain surgery. You can diagram each structure with
a specific configuration of flowchart symbols.
Understanding the Three Basic Structures
The first of these three basic structures is a sequence, as
shown in the figure. With a sequence structure, you
perform an action or task, and then you perform the next
action, in order. A sequence can contain any number of
tasks, but there is no option to branch off and skip any of
the tasks. Once you start a series of actions in a sequence,
you must continue step by step until the sequence ends.
Understanding the Three Basic Structures
As an example, driving directions often are listed as a sequence. To tell a
friend how to get to your house from school, you might provide the
following sequence, in which one step follows the other and no steps can be
skipped:
go north on First Avenue for 3 miles
turn left on Washington Boulevard
go west on Washington for 2 miles
stop at 634 Washington
Understanding the Three Basic Structures
The second of the three structures is a
selection structure or decision
structure, as shown in the figure. With
this structure, you ask a question and,
depending on the answer, you take one of
two courses of action. Then, no matter
which path you follow, you continue with
the next task.
Understanding the Three Basic Structures
Some people call the selection structure an if-then-else because it fits the
following statement:
if someCondition is true then
do oneProcess
else
do theOtherProcess
endif
Understanding the Three Basic Structures
For example, you might provide part of the directions to your house as
follows:
if traffic is backed up on Washington Boulevard then
continue for 1 block on First Avenue and turn left on Adams Lane
else
turn left on Washington Boulevard
endif
Understanding the Three Basic Structures
Similarly, a payroll program might include a statement such as:
if hoursWorked is more than 40 then
calculate regularPay and overtimePay
else
calculate regularPay
endif
Understanding the Three Basic Structures
These if-else examples can also be
called dual-alternative ifs (or
dual-alternative selections),
because they contain two
alternatives—the action taken when
the tested condition is true and the
action taken when it is false. Note
that it is perfectly correct for one
branch of the selection to be a “do
nothing” branch. In each of the
following examples, an action is
taken only when the tested
condition is true:
if it is raining then
take an umbrella
endif
if employee participates in the dental plan then
deduct $40 from employee gross pay
endif
Understanding the Three Basic Structures
The previous examples without else clauses
are single-alternative ifs (or single-
alternative selections); a diagram of their
structure is shown in the figure. In these
cases, you do not take any special action if
it is not raining or if the employee does not
belong to the dental plan. The case in
which nothing is done is often called the
null case.
Understanding the Three Basic Structures
The last of the three basic structures, shown in Figure 3-5, is a loop. In a
loop structure, you continue to repeat actions while a condition remains
true. The action or actions that occur
within the loop are the loop body. In
the most common type of loop, a
condition is evaluated; if the answer is
true, you execute the loop body and
evaluate the condition again. If the
condition is still true, you execute the
loop body again and then reevaluate the
original condition. This continues until
the condition becomes false, and then you exit the structure.
Understanding the Three Basic Structures
You may hear programmers refer to looping as repetition or iteration.
Some programmers call this structure a while…do, or more simply, a while
loop, because it fits the following statement:
while testCondition continues to be true
do someProcess
endwhile
Understanding the Three Basic Structures
When you provide directions to your house, part of the directions might be:
while the address of the house you are passing remains below 634
travel forward to the next house
look at the address on the house
endwhile
Understanding the Three Basic Structures
You encounter examples of looping every day, as in each of the following:
while you continue to be hungry
take another bite of food
determine whether you still feel hungry
endwhile
while unread pages remain in the reading assignment
read another unread page
determine whether there are more pages to be read
endwhile
Understanding the Three Basic Structures
All logic problems can be solved using only these three structures—
sequence, selection, and loop. The structures can be combined in an infinite
number of ways. For example, you can have a sequence of tasks followed by
a selection, or a loop followed by a sequence. Attaching structures end to
end is called stacking structures.
Understanding the Three Basic Structures
For example, the figure shows a
structured flowchart achieved by
stacking structures, and shows
pseudocode that follows the
flowchart logic.
The pseudocode shows a sequence,
followed by a selection, followed by
a loop.
Understanding the Three Basic Structures
First stepA and stepB execute in sequence. Then a selection structure starts
with the test of conditionC. The instruction that follows the if clause (stepD)
occurs when its tested condition is true, the instruction that follows else
(stepE) occurs when the tested condition is false, and any instructions that
follow endif occur in either case. In other words, statements beyond the
endif statement are “outside” the decision structure. Similarly, the
endwhile statement shows where the loop structure ends. While conditionF
continues to be true, stepG continues to execute. If any statements
followed the endwhile statement, they would be outside of, and not a part
of, the loop.
Understanding the Three Basic Structures
Besides stacking structures, you can
replace any individual steps in a
structured flowchart diagram or
pseudocode with additional structures.
In other words, any sequence,
selection, or loop can contain other
sequences, selections, or loops. For
example, you can have a sequence of
three tasks on one side of a selection,
as shown. Placing a structure within
another structure is called nesting
structures.
Understanding the Three Basic Structures
In the pseudocode for the logic
shown, the indentation shows
that all three statements (stepJ,
stepK, and stepL) must execute
if conditionH is true. The three
statements constitute a block,
or a group of statements that
executes as a single unit.
Understanding the Three Basic Structures
In place of one of the steps in
the sequence, you can insert
another structure. In the figure,
the process named stepK has
been replaced with a loop
structure that begins with a test
of the condition named
conditionM.
Understanding the Three Basic Structures
In the pseudocode shown, notice that if and endif are vertically aligned.
This shows that they are all “on the same level.” Similarly, stepJ, while,
endwhile, and stepL are aligned, and they are evenly indented. In the
flowchart, you could draw a vertical line through the symbols containing
stepJ, the entry and exit points of the while loop, and stepL. The flowchart
and the pseudocode represent exactly the same logic.
Understanding the Three Basic Structures
There is no limit to the number of levels you
can create when you nest and stack
structures. For example, the figure shows
logic that has been made more complicated
by replacing stepN with a selection. The
structure that performs stepP or stepQ
based on the outcome of conditionO is
nested within the loop that is controlled by
conditionM. In the pseudocode, notice how
the if, else, and endif that describe the
condition selection are aligned with each
other and within the while structure that is
controlled by conditionM.
Understanding the Three Basic Structures
The possible combinations of logical structures are endless, but each
segment of a structured
program is a sequence, a
selection, or a loop. The
three structures are shown
together. Notice that each
structure has one entry
point and one exit point.
One structure can attach to
another only at one of these
points.
Summary
A structured program has the following characteristics:
• A structured program includes only combinations of the three basic
structures— sequence, selection, and loop. Any structured program might
contain one, two, or all three types of structures.
• Each of the structures has a single entry point and a single exit point.
• Structures can be stacked or connected to one another only at their entry
or exit points.
• Any structure can be nested within another structure.
THANK YOU

More Related Content

What's hot

Chapter 2 database environment
Chapter 2 database environmentChapter 2 database environment
Chapter 2 database environment>. <
 
System analysis and design Part2
System analysis and design Part2System analysis and design Part2
System analysis and design Part2
Joel Briza
 
Unified modeling language diagrams
Unified modeling language diagramsUnified modeling language diagrams
Unified modeling language diagramsAlaa Ahmed
 
Requirements modeling
Requirements modelingRequirements modeling
Requirements modeling
AnanthiP8
 
All data models in dbms
All data models in dbmsAll data models in dbms
All data models in dbmsNaresh Kumar
 
Structural modeling and analysis
Structural modeling and analysisStructural modeling and analysis
Structural modeling and analysis
JIGAR MAKHIJA
 
Object Oriented Analysis and Design
Object Oriented Analysis and DesignObject Oriented Analysis and Design
Object Oriented Analysis and DesignHaitham El-Ghareeb
 
1. Fundamental Concept - Data Structures using C++ by Varsha Patil
1. Fundamental Concept - Data Structures using C++ by Varsha Patil1. Fundamental Concept - Data Structures using C++ by Varsha Patil
1. Fundamental Concept - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
Data models
Data modelsData models
Data models
Dhani Ahmad
 
16. Concurrency Control in DBMS
16. Concurrency Control in DBMS16. Concurrency Control in DBMS
16. Concurrency Control in DBMSkoolkampus
 
Architectural views
Architectural viewsArchitectural views
Architectural viewsSaleem Khan
 
serializability in dbms
serializability in dbmsserializability in dbms
serializability in dbms
Saranya Natarajan
 
Relational algebra ppt
Relational algebra pptRelational algebra ppt
Relational algebra ppt
GirdharRatne
 
Fundamentals of Database system
Fundamentals of Database systemFundamentals of Database system
Fundamentals of Database system
philipsinter
 
System Analysis Fact Finding Methods
System Analysis Fact Finding MethodsSystem Analysis Fact Finding Methods
System Analysis Fact Finding Methods
Moshikur Rahman
 
Unit 1-Data Science Process Overview.pptx
Unit 1-Data Science Process Overview.pptxUnit 1-Data Science Process Overview.pptx
Unit 1-Data Science Process Overview.pptx
Anusuya123
 
15. Transactions in DBMS
15. Transactions in DBMS15. Transactions in DBMS
15. Transactions in DBMSkoolkampus
 
Multidimensional data models
Multidimensional data  modelsMultidimensional data  models
Multidimensional data models
774474
 
Transaction Processing Concept
Transaction Processing ConceptTransaction Processing Concept
Transaction Processing Concept
Nishant Munjal
 
File organization 1
File organization 1File organization 1
File organization 1
Rupali Rana
 

What's hot (20)

Chapter 2 database environment
Chapter 2 database environmentChapter 2 database environment
Chapter 2 database environment
 
System analysis and design Part2
System analysis and design Part2System analysis and design Part2
System analysis and design Part2
 
Unified modeling language diagrams
Unified modeling language diagramsUnified modeling language diagrams
Unified modeling language diagrams
 
Requirements modeling
Requirements modelingRequirements modeling
Requirements modeling
 
All data models in dbms
All data models in dbmsAll data models in dbms
All data models in dbms
 
Structural modeling and analysis
Structural modeling and analysisStructural modeling and analysis
Structural modeling and analysis
 
Object Oriented Analysis and Design
Object Oriented Analysis and DesignObject Oriented Analysis and Design
Object Oriented Analysis and Design
 
1. Fundamental Concept - Data Structures using C++ by Varsha Patil
1. Fundamental Concept - Data Structures using C++ by Varsha Patil1. Fundamental Concept - Data Structures using C++ by Varsha Patil
1. Fundamental Concept - Data Structures using C++ by Varsha Patil
 
Data models
Data modelsData models
Data models
 
16. Concurrency Control in DBMS
16. Concurrency Control in DBMS16. Concurrency Control in DBMS
16. Concurrency Control in DBMS
 
Architectural views
Architectural viewsArchitectural views
Architectural views
 
serializability in dbms
serializability in dbmsserializability in dbms
serializability in dbms
 
Relational algebra ppt
Relational algebra pptRelational algebra ppt
Relational algebra ppt
 
Fundamentals of Database system
Fundamentals of Database systemFundamentals of Database system
Fundamentals of Database system
 
System Analysis Fact Finding Methods
System Analysis Fact Finding MethodsSystem Analysis Fact Finding Methods
System Analysis Fact Finding Methods
 
Unit 1-Data Science Process Overview.pptx
Unit 1-Data Science Process Overview.pptxUnit 1-Data Science Process Overview.pptx
Unit 1-Data Science Process Overview.pptx
 
15. Transactions in DBMS
15. Transactions in DBMS15. Transactions in DBMS
15. Transactions in DBMS
 
Multidimensional data models
Multidimensional data  modelsMultidimensional data  models
Multidimensional data models
 
Transaction Processing Concept
Transaction Processing ConceptTransaction Processing Concept
Transaction Processing Concept
 
File organization 1
File organization 1File organization 1
File organization 1
 

Similar to Understanding the Three Basic Structures

C Programming - Decision making, Looping
C  Programming - Decision making, LoopingC  Programming - Decision making, Looping
C Programming - Decision making, Looping
MURALIDHAR R
 
ntroduction to Ethology Part 2 Quantifying BehaviorBio 112 Lab, S.docx
ntroduction to Ethology Part 2 Quantifying BehaviorBio 112 Lab, S.docxntroduction to Ethology Part 2 Quantifying BehaviorBio 112 Lab, S.docx
ntroduction to Ethology Part 2 Quantifying BehaviorBio 112 Lab, S.docx
gabriellabre8fr
 
Introduction to Ethology Part 2 Quantifying BehaviorBio 112 Lab.docx
Introduction to Ethology Part 2 Quantifying BehaviorBio 112 Lab.docxIntroduction to Ethology Part 2 Quantifying BehaviorBio 112 Lab.docx
Introduction to Ethology Part 2 Quantifying BehaviorBio 112 Lab.docx
mariuse18nolet
 
Lesson flow charts 1
Lesson flow charts 1Lesson flow charts 1
Lesson flow charts 1
Lexume1
 
In order to study and measure behavior you must break the behavi.docx
In order to study and measure behavior you must break the behavi.docxIn order to study and measure behavior you must break the behavi.docx
In order to study and measure behavior you must break the behavi.docx
rochellscroop
 
Intro To C++ - Class 09 - Control Statements: Part 1
Intro To C++ - Class 09 - Control Statements: Part 1Intro To C++ - Class 09 - Control Statements: Part 1
Intro To C++ - Class 09 - Control Statements: Part 1
Blue Elephant Consulting
 
Time series
Time seriesTime series
Chapter 5 (final)
Chapter 5 (final)Chapter 5 (final)
Chapter 5 (final)
Nateshwar Kamlesh
 
Introduction to loops cpu
Introduction to loops  cpuIntroduction to loops  cpu
Introduction to loops cpu
Harsh Gupta
 
Loops
LoopsLoops
Conditional statements & Loops
Conditional statements & LoopsConditional statements & Loops
Conditional statements & Loops
saifullahbhatti99
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
Hossain Md Shakhawat
 
Mathematical Logic Part 2
Mathematical Logic Part 2Mathematical Logic Part 2
Mathematical Logic Part 2
blaircomp2003
 
Java chapter 3
Java chapter 3Java chapter 3
Java chapter 3
Abdii Rashid
 
Eu assistant exams_workbook_eu_training
Eu assistant exams_workbook_eu_trainingEu assistant exams_workbook_eu_training
Eu assistant exams_workbook_eu_trainingeuinmotion
 
EU Assistant Exams Workbook - Volume I
EU Assistant Exams Workbook - Volume IEU Assistant Exams Workbook - Volume I
EU Assistant Exams Workbook - Volume I
euinmotion
 
Wk 5 Individual Preparing for Working in Teams [due Day#]Top of.docx
Wk 5 Individual Preparing for Working in Teams [due Day#]Top of.docxWk 5 Individual Preparing for Working in Teams [due Day#]Top of.docx
Wk 5 Individual Preparing for Working in Teams [due Day#]Top of.docx
helzerpatrina
 
C Constructs (C Statements & Loop)
C Constructs (C Statements & Loop)C Constructs (C Statements & Loop)
02 - Prepcode
02 - Prepcode02 - Prepcode
02 - Prepcode
thewhiteafrican
 

Similar to Understanding the Three Basic Structures (20)

C Programming - Decision making, Looping
C  Programming - Decision making, LoopingC  Programming - Decision making, Looping
C Programming - Decision making, Looping
 
ntroduction to Ethology Part 2 Quantifying BehaviorBio 112 Lab, S.docx
ntroduction to Ethology Part 2 Quantifying BehaviorBio 112 Lab, S.docxntroduction to Ethology Part 2 Quantifying BehaviorBio 112 Lab, S.docx
ntroduction to Ethology Part 2 Quantifying BehaviorBio 112 Lab, S.docx
 
Introduction to Ethology Part 2 Quantifying BehaviorBio 112 Lab.docx
Introduction to Ethology Part 2 Quantifying BehaviorBio 112 Lab.docxIntroduction to Ethology Part 2 Quantifying BehaviorBio 112 Lab.docx
Introduction to Ethology Part 2 Quantifying BehaviorBio 112 Lab.docx
 
Lesson flow charts 1
Lesson flow charts 1Lesson flow charts 1
Lesson flow charts 1
 
In order to study and measure behavior you must break the behavi.docx
In order to study and measure behavior you must break the behavi.docxIn order to study and measure behavior you must break the behavi.docx
In order to study and measure behavior you must break the behavi.docx
 
Intro To C++ - Class 09 - Control Statements: Part 1
Intro To C++ - Class 09 - Control Statements: Part 1Intro To C++ - Class 09 - Control Statements: Part 1
Intro To C++ - Class 09 - Control Statements: Part 1
 
Time series
Time seriesTime series
Time series
 
Chapter 5 (final)
Chapter 5 (final)Chapter 5 (final)
Chapter 5 (final)
 
Introduction to loops cpu
Introduction to loops  cpuIntroduction to loops  cpu
Introduction to loops cpu
 
Loops
LoopsLoops
Loops
 
Conditional statements & Loops
Conditional statements & LoopsConditional statements & Loops
Conditional statements & Loops
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
 
Mathematical Logic Part 2
Mathematical Logic Part 2Mathematical Logic Part 2
Mathematical Logic Part 2
 
Logic Summaries
Logic SummariesLogic Summaries
Logic Summaries
 
Java chapter 3
Java chapter 3Java chapter 3
Java chapter 3
 
Eu assistant exams_workbook_eu_training
Eu assistant exams_workbook_eu_trainingEu assistant exams_workbook_eu_training
Eu assistant exams_workbook_eu_training
 
EU Assistant Exams Workbook - Volume I
EU Assistant Exams Workbook - Volume IEU Assistant Exams Workbook - Volume I
EU Assistant Exams Workbook - Volume I
 
Wk 5 Individual Preparing for Working in Teams [due Day#]Top of.docx
Wk 5 Individual Preparing for Working in Teams [due Day#]Top of.docxWk 5 Individual Preparing for Working in Teams [due Day#]Top of.docx
Wk 5 Individual Preparing for Working in Teams [due Day#]Top of.docx
 
C Constructs (C Statements & Loop)
C Constructs (C Statements & Loop)C Constructs (C Statements & Loop)
C Constructs (C Statements & Loop)
 
02 - Prepcode
02 - Prepcode02 - Prepcode
02 - Prepcode
 

More from Ar Kyu Dee

Cube
CubeCube
Cuboid
CuboidCuboid
Cuboid
Ar Kyu Dee
 
Learning outcome 2 prepare make pcb modules
Learning outcome 2 prepare make pcb modulesLearning outcome 2 prepare make pcb modules
Learning outcome 2 prepare make pcb modules
Ar Kyu Dee
 
Learning outcome 1 prepare to assemble electronic products
Learning outcome 1 prepare to assemble electronic productsLearning outcome 1 prepare to assemble electronic products
Learning outcome 1 prepare to assemble electronic products
Ar Kyu Dee
 
Using Pseudocode Statements and Flowchart Symbols
Using Pseudocode Statements and Flowchart SymbolsUsing Pseudocode Statements and Flowchart Symbols
Using Pseudocode Statements and Flowchart Symbols
Ar Kyu Dee
 
Understanding Simple Program Logic
Understanding Simple Program LogicUnderstanding Simple Program Logic
Understanding Simple Program Logic
Ar Kyu Dee
 
Understanding Computer Systems
Understanding Computer SystemsUnderstanding Computer Systems
Understanding Computer Systems
Ar Kyu Dee
 

More from Ar Kyu Dee (7)

Cube
CubeCube
Cube
 
Cuboid
CuboidCuboid
Cuboid
 
Learning outcome 2 prepare make pcb modules
Learning outcome 2 prepare make pcb modulesLearning outcome 2 prepare make pcb modules
Learning outcome 2 prepare make pcb modules
 
Learning outcome 1 prepare to assemble electronic products
Learning outcome 1 prepare to assemble electronic productsLearning outcome 1 prepare to assemble electronic products
Learning outcome 1 prepare to assemble electronic products
 
Using Pseudocode Statements and Flowchart Symbols
Using Pseudocode Statements and Flowchart SymbolsUsing Pseudocode Statements and Flowchart Symbols
Using Pseudocode Statements and Flowchart Symbols
 
Understanding Simple Program Logic
Understanding Simple Program LogicUnderstanding Simple Program Logic
Understanding Simple Program Logic
 
Understanding Computer Systems
Understanding Computer SystemsUnderstanding Computer Systems
Understanding Computer Systems
 

Recently uploaded

S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
Bisnar Chase Personal Injury Attorneys
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Ashish Kohli
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
ArianaBusciglio
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 

Recently uploaded (20)

S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 

Understanding the Three Basic Structures

  • 2. Understanding the Three Basic Structures In the mid-1960s, mathematicians proved that any program, no matter how complicated, can be constructed using one or more of only three structures. A structure is a basic unit of programming logic; each structure is one of the following: • Sequence • Selection • Loop With these three structures alone, you can diagram any task, from doubling a number to performing brain surgery. You can diagram each structure with a specific configuration of flowchart symbols.
  • 3. Understanding the Three Basic Structures The first of these three basic structures is a sequence, as shown in the figure. With a sequence structure, you perform an action or task, and then you perform the next action, in order. A sequence can contain any number of tasks, but there is no option to branch off and skip any of the tasks. Once you start a series of actions in a sequence, you must continue step by step until the sequence ends.
  • 4. Understanding the Three Basic Structures As an example, driving directions often are listed as a sequence. To tell a friend how to get to your house from school, you might provide the following sequence, in which one step follows the other and no steps can be skipped: go north on First Avenue for 3 miles turn left on Washington Boulevard go west on Washington for 2 miles stop at 634 Washington
  • 5. Understanding the Three Basic Structures The second of the three structures is a selection structure or decision structure, as shown in the figure. With this structure, you ask a question and, depending on the answer, you take one of two courses of action. Then, no matter which path you follow, you continue with the next task.
  • 6. Understanding the Three Basic Structures Some people call the selection structure an if-then-else because it fits the following statement: if someCondition is true then do oneProcess else do theOtherProcess endif
  • 7. Understanding the Three Basic Structures For example, you might provide part of the directions to your house as follows: if traffic is backed up on Washington Boulevard then continue for 1 block on First Avenue and turn left on Adams Lane else turn left on Washington Boulevard endif
  • 8. Understanding the Three Basic Structures Similarly, a payroll program might include a statement such as: if hoursWorked is more than 40 then calculate regularPay and overtimePay else calculate regularPay endif
  • 9. Understanding the Three Basic Structures These if-else examples can also be called dual-alternative ifs (or dual-alternative selections), because they contain two alternatives—the action taken when the tested condition is true and the action taken when it is false. Note that it is perfectly correct for one branch of the selection to be a “do nothing” branch. In each of the following examples, an action is taken only when the tested condition is true: if it is raining then take an umbrella endif if employee participates in the dental plan then deduct $40 from employee gross pay endif
  • 10. Understanding the Three Basic Structures The previous examples without else clauses are single-alternative ifs (or single- alternative selections); a diagram of their structure is shown in the figure. In these cases, you do not take any special action if it is not raining or if the employee does not belong to the dental plan. The case in which nothing is done is often called the null case.
  • 11. Understanding the Three Basic Structures The last of the three basic structures, shown in Figure 3-5, is a loop. In a loop structure, you continue to repeat actions while a condition remains true. The action or actions that occur within the loop are the loop body. In the most common type of loop, a condition is evaluated; if the answer is true, you execute the loop body and evaluate the condition again. If the condition is still true, you execute the loop body again and then reevaluate the original condition. This continues until the condition becomes false, and then you exit the structure.
  • 12. Understanding the Three Basic Structures You may hear programmers refer to looping as repetition or iteration. Some programmers call this structure a while…do, or more simply, a while loop, because it fits the following statement: while testCondition continues to be true do someProcess endwhile
  • 13. Understanding the Three Basic Structures When you provide directions to your house, part of the directions might be: while the address of the house you are passing remains below 634 travel forward to the next house look at the address on the house endwhile
  • 14. Understanding the Three Basic Structures You encounter examples of looping every day, as in each of the following: while you continue to be hungry take another bite of food determine whether you still feel hungry endwhile while unread pages remain in the reading assignment read another unread page determine whether there are more pages to be read endwhile
  • 15. Understanding the Three Basic Structures All logic problems can be solved using only these three structures— sequence, selection, and loop. The structures can be combined in an infinite number of ways. For example, you can have a sequence of tasks followed by a selection, or a loop followed by a sequence. Attaching structures end to end is called stacking structures.
  • 16. Understanding the Three Basic Structures For example, the figure shows a structured flowchart achieved by stacking structures, and shows pseudocode that follows the flowchart logic. The pseudocode shows a sequence, followed by a selection, followed by a loop.
  • 17. Understanding the Three Basic Structures First stepA and stepB execute in sequence. Then a selection structure starts with the test of conditionC. The instruction that follows the if clause (stepD) occurs when its tested condition is true, the instruction that follows else (stepE) occurs when the tested condition is false, and any instructions that follow endif occur in either case. In other words, statements beyond the endif statement are “outside” the decision structure. Similarly, the endwhile statement shows where the loop structure ends. While conditionF continues to be true, stepG continues to execute. If any statements followed the endwhile statement, they would be outside of, and not a part of, the loop.
  • 18. Understanding the Three Basic Structures Besides stacking structures, you can replace any individual steps in a structured flowchart diagram or pseudocode with additional structures. In other words, any sequence, selection, or loop can contain other sequences, selections, or loops. For example, you can have a sequence of three tasks on one side of a selection, as shown. Placing a structure within another structure is called nesting structures.
  • 19. Understanding the Three Basic Structures In the pseudocode for the logic shown, the indentation shows that all three statements (stepJ, stepK, and stepL) must execute if conditionH is true. The three statements constitute a block, or a group of statements that executes as a single unit.
  • 20. Understanding the Three Basic Structures In place of one of the steps in the sequence, you can insert another structure. In the figure, the process named stepK has been replaced with a loop structure that begins with a test of the condition named conditionM.
  • 21. Understanding the Three Basic Structures In the pseudocode shown, notice that if and endif are vertically aligned. This shows that they are all “on the same level.” Similarly, stepJ, while, endwhile, and stepL are aligned, and they are evenly indented. In the flowchart, you could draw a vertical line through the symbols containing stepJ, the entry and exit points of the while loop, and stepL. The flowchart and the pseudocode represent exactly the same logic.
  • 22. Understanding the Three Basic Structures There is no limit to the number of levels you can create when you nest and stack structures. For example, the figure shows logic that has been made more complicated by replacing stepN with a selection. The structure that performs stepP or stepQ based on the outcome of conditionO is nested within the loop that is controlled by conditionM. In the pseudocode, notice how the if, else, and endif that describe the condition selection are aligned with each other and within the while structure that is controlled by conditionM.
  • 23. Understanding the Three Basic Structures The possible combinations of logical structures are endless, but each segment of a structured program is a sequence, a selection, or a loop. The three structures are shown together. Notice that each structure has one entry point and one exit point. One structure can attach to another only at one of these points.
  • 24. Summary A structured program has the following characteristics: • A structured program includes only combinations of the three basic structures— sequence, selection, and loop. Any structured program might contain one, two, or all three types of structures. • Each of the structures has a single entry point and a single exit point. • Structures can be stacked or connected to one another only at their entry or exit points. • Any structure can be nested within another structure.