SlideShare a Scribd company logo
Programming Logic and Design
Eighth Edition
Chapter 3
Understanding Structure
Objectives
In this chapter, you will learn about:
• The disadvantages of unstructured spaghetti code
• The three basic structures—sequence, selection, and
loop
• Using a priming input to structure a program
• The need for structure
• Recognizing structure
• Structuring and modularizing unstructured logic
2Programming Logic and Design, Eighth Edition
The Disadvantages of Unstructured
Spaghetti Code
• Spaghetti code
– Logically snarled program statements
– Often a complicated mess
– Programs often work but are difficult to read and maintain
– Confusing and prone to error
• Unstructured programs
– Do not follow the rules of structured logic
• Structured programs
– Follow the rules of structured logic
3Programming Logic and Design, Eighth Edition
4Programming Logic and Design, Eighth Edition Figure 3-1 Spaghetti code logic for washing a dog
Understanding the Three Basic
Structures
• Structure
– Basic unit of programming logic
– Sequence structure
• Perform actions or tasks in order
• No branching or skipping any task
– Selection structure (decision structure)
• Ask a question, take one of two actions
• Often called if-then-else
• Dual-alternative ifs or single-alternative ifs
– Loop structure
• Repeat actions while a condition remains true
5Programming Logic and Design, Eighth Edition
Understanding the Three Basic
Structures (continued)
6Programming Logic and Design, Eighth Edition
Figure 3-2 Sequence structure
Understanding the Three Basic
Structures (continued)
7Programming Logic and Design, Eighth Edition
Figure 3-3 Selection structure
Understanding the Three Basic
Structures (continued)
• Dual-alternative ifs
– Contains two alternatives
– The if-then-else structure
8Programming Logic and Design, Eighth Edition
if someCondition is true then
do oneProcess
else
do theOtherProcess
endif
Understanding the Three Basic
Structures (continued)
• Single-alternative ifs
– An else clause is not required
• null case
– Situation where nothing is done
9Programming Logic and Design, Eighth Edition
if employee belongs to dentalPlan then
deduct $40 from employeeGrossPay
Understanding the Three Basic
Structures (continued)
10Programming Logic and Design, Eighth Edition
Figure 3-4 Single-alternative selection structure
Understanding the Three Basic
Structures (continued)
• Loop structure
– Repeats a set of actions while a condition remains true
• Loop body
– Also called repetition or iteration
– Condition is tested first in the most common form of loop
– The while…do or while loop
11Programming Logic and Design, Eighth Edition
Understanding the Three Basic
Structures (continued)
12Programming Logic and Design, Eighth Edition
Figure 3-5 Loop structure
Understanding the Three Basic
Structures (continued)
• Loop structure
13Programming Logic and Design, Eighth Edition
while testCondition continues to be true
do someProcess
endwhile
while you continue to be hungry
take another bite of food
determine if you still feel hungry
endwhile
Understanding the Three Basic
Structures (continued)
• All logic problems can be solved using only sequence,
selection, and loop
• Structures can be combined in an infinite number of
ways
• Stacking structures
– Attaching structures end-to-end
• End-structure statement
– Indicates the end of a structure
– The endif statement ends an if-then-else structure
– The endwhile statement ends a loop structure
14Programming Logic and Design, Eighth Edition
Understanding the Three Basic
Structures (continued)
15Programming Logic and Design, Eighth Edition
Figure 3-6 Structured flowchart and pseudocode with three stacked structures
Understanding the Three Basic
Structures (continued)
• Any individual task or step in a structure can be
replaced by a structure
• Nesting structures
– Placing one structure within another
– Indent the nested structure’s statements
• Block
– A group of statements that execute as a single unit
16Programming Logic and Design, Eighth Edition
Understanding the Three Basic
Structures (continued)
17Programming Logic and Design, Eighth Edition
Figure 3-7 Flowchart and pseudocode showing nested structures—
a sequence nested within a selection
Understanding the Three Basic
Structures (continued)
18Programming Logic and Design, Eighth Edition
Figure 3-8 Flowchart and pseudocode showing nested structures—
a loop nested within a sequence, nested within a selection
Understanding the Three Basic
Structures (continued)
19Programming Logic and Design, Eighth Edition
Figure 3-9 Flowchart and pseudocode for a selection within
a loop within a sequence within a selection
Understanding the Three Basic
Structures (continued)
• Structured programs have the following
characteristics:
– Include only combinations of the three basic structures
– Each structure 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
20Programming Logic and Design, Eighth Edition
Using a Priming Input to Structure
a Program
• Priming input (or priming read)
– Reads the first input data record
– Is outside the loop that reads the rest of the records
– Helps keep the program structured
• Analyze a flowchart for structure one step at a time
• Watch for unstructured loops that do not follow this
order
– First ask a question
– Take action based on the answer
– Return to ask the question again
21Programming Logic and Design, Eighth Edition
Using a Priming Input to Structure
a Program (continued)
22Programming Logic and Design, Eighth Edition
Figure 3-14 Structured, but nonfunctional, flowchart of number-doubling problem
Using a Priming Input to Structure
a Program (continued)
23Programming Logic and Design, Eighth Edition
Figure 3-15 Functional but unstructured flowchart
24Programming Logic and Design, Eighth Edition
Figure 3-16 Functional, structured flowchart for the number-doubling problem
25Programming Logic and Design, Eighth Edition
Figure 3-17 Structured but incorrect solution to the number-doubling problem
Understanding the Reasons for
Structure
• Clarity—unstructured programs are confusing
• Professionalism—other programmers expect it
• Efficiency—most languages support it
• Maintenance —other programmers find it easier to
read
• Modularity —easily broken down into modules
26Programming Logic and Design, Eighth Edition
27Programming Logic and Design, Eighth Edition
Figure 3-18 Example 1
Structured Flowcharts?
Recognizing Structure
Figure 3-19 Example 2
Recognizing
Structure (continued)
28Programming Logic and Design, Eighth Edition
Figure 3-20 Example 3
An Unstructured Flowchart
29Programming Logic and Design, Eighth Edition
Figure 3-21 Steps to structure the dog-
washing process
Recognizing
Structure (continued)
30Programming Logic and Design, Eighth Edition
Figure 3-22 Structured dog-washing
flowchart and pseudocode
Recognizing
Structure (continued)
31Programming Logic and Design, Eighth Edition
Figure 3-23 Modularized version of the
dog-washing program
Recognizing
Structure (continued)
Summary
• Spaghetti code
– Statements that do not follow rules of structured logic
• Three basic structures
– Sequence, selection, and loop
– Combined by stacking and nesting
• Priming input
– Statement that reads the first input value prior to starting
a structured loop
32Programming Logic and Design, Eighth Edition
Summary (continued)
• Structured techniques promote:
– Clarity
– Professionalism
– Efficiency
– Modularity
• Flowcharts can be made structured by untangling
• Logical steps can be rewritten to conform to the
three structures
33Programming Logic and Design, Eighth Edition

More Related Content

What's hot

Architecture design in software engineering
Architecture design in software engineeringArchitecture design in software engineering
Architecture design in software engineering
Preeti Mishra
 
Parallel processing
Parallel processingParallel processing
Parallel processing
Syed Zaid Irshad
 
Multi threaded programming
Multi threaded programmingMulti threaded programming
Multi threaded programming
AnyapuPranav
 
SDLC - Software Development Life Cycle
SDLC - Software Development Life CycleSDLC - Software Development Life Cycle
SDLC - Software Development Life Cycle
Suresh Koujalagi
 
Ch5: Threads (Operating System)
Ch5: Threads (Operating System)Ch5: Threads (Operating System)
Ch5: Threads (Operating System)
Ahmar Hashmi
 
Software requirements engineering problems and challenges erp implementation ...
Software requirements engineering problems and challenges erp implementation ...Software requirements engineering problems and challenges erp implementation ...
Software requirements engineering problems and challenges erp implementation ...
Dr. Hamdan Al-Sabri
 
Chapter 4 software design
Chapter 4  software designChapter 4  software design
Chapter 4 software design
Cliftone Mullah
 
Software Generic Design Process.
Software Generic Design Process.Software Generic Design Process.
Software Generic Design Process.
Syed Hassan Ali
 
Software en tiempo real
Software en tiempo realSoftware en tiempo real
Software en tiempo real
Aeivans
 
Typical Embedded System
Typical Embedded SystemTypical Embedded System
Typical Embedded System
anand hd
 
Reqmt_Engn.ppt
Reqmt_Engn.pptReqmt_Engn.ppt
Reqmt_Engn.ppt
DrCMeenakshiVISTAS
 
Comparison of Software Engineering Models
Comparison of Software Engineering  ModelsComparison of Software Engineering  Models
Comparison of Software Engineering Models
tahir iqbal
 
Software architecture design ppt
Software architecture design pptSoftware architecture design ppt
Software architecture design ppt
farazimlak
 
Uml in software engineering
Uml in software engineeringUml in software engineering
Uml in software engineering
Mubashir Jutt
 
Chapter19 rapid application development
Chapter19 rapid application developmentChapter19 rapid application development
Chapter19 rapid application development
Dhani Ahmad
 
RISC Vs CISC, Harvard v/s Van Neumann
RISC Vs CISC, Harvard v/s Van NeumannRISC Vs CISC, Harvard v/s Van Neumann
RISC Vs CISC, Harvard v/s Van Neumann
Ravikumar Tiwari
 
Uml structural diagrams
Uml structural diagramsUml structural diagrams
Uml structural diagrams
Swathy T
 
4+1 view model
4+1 view model4+1 view model
4+1 view model
Shobana Chokkalingam
 
Software Engineering - chp4- design patterns
Software Engineering - chp4- design patternsSoftware Engineering - chp4- design patterns
Software Engineering - chp4- design patterns
Lilia Sfaxi
 
Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design pattern
Mindfire Solutions
 

What's hot (20)

Architecture design in software engineering
Architecture design in software engineeringArchitecture design in software engineering
Architecture design in software engineering
 
Parallel processing
Parallel processingParallel processing
Parallel processing
 
Multi threaded programming
Multi threaded programmingMulti threaded programming
Multi threaded programming
 
SDLC - Software Development Life Cycle
SDLC - Software Development Life CycleSDLC - Software Development Life Cycle
SDLC - Software Development Life Cycle
 
Ch5: Threads (Operating System)
Ch5: Threads (Operating System)Ch5: Threads (Operating System)
Ch5: Threads (Operating System)
 
Software requirements engineering problems and challenges erp implementation ...
Software requirements engineering problems and challenges erp implementation ...Software requirements engineering problems and challenges erp implementation ...
Software requirements engineering problems and challenges erp implementation ...
 
Chapter 4 software design
Chapter 4  software designChapter 4  software design
Chapter 4 software design
 
Software Generic Design Process.
Software Generic Design Process.Software Generic Design Process.
Software Generic Design Process.
 
Software en tiempo real
Software en tiempo realSoftware en tiempo real
Software en tiempo real
 
Typical Embedded System
Typical Embedded SystemTypical Embedded System
Typical Embedded System
 
Reqmt_Engn.ppt
Reqmt_Engn.pptReqmt_Engn.ppt
Reqmt_Engn.ppt
 
Comparison of Software Engineering Models
Comparison of Software Engineering  ModelsComparison of Software Engineering  Models
Comparison of Software Engineering Models
 
Software architecture design ppt
Software architecture design pptSoftware architecture design ppt
Software architecture design ppt
 
Uml in software engineering
Uml in software engineeringUml in software engineering
Uml in software engineering
 
Chapter19 rapid application development
Chapter19 rapid application developmentChapter19 rapid application development
Chapter19 rapid application development
 
RISC Vs CISC, Harvard v/s Van Neumann
RISC Vs CISC, Harvard v/s Van NeumannRISC Vs CISC, Harvard v/s Van Neumann
RISC Vs CISC, Harvard v/s Van Neumann
 
Uml structural diagrams
Uml structural diagramsUml structural diagrams
Uml structural diagrams
 
4+1 view model
4+1 view model4+1 view model
4+1 view model
 
Software Engineering - chp4- design patterns
Software Engineering - chp4- design patternsSoftware Engineering - chp4- design patterns
Software Engineering - chp4- design patterns
 
Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design pattern
 

Viewers also liked

Computer programming language concept
Computer programming language conceptComputer programming language concept
Computer programming language concept
Afiq Sajuri
 
8150.graphs
8150.graphs8150.graphs
8150.graphs
Jonghoon Park
 
Java practice programs for beginners
Java practice programs for beginnersJava practice programs for beginners
Java practice programs for beginners
ishan0019
 
introduction to database
 introduction to database introduction to database
introduction to database
Akif shexi
 
Sentiment Analysis
Sentiment AnalysisSentiment Analysis
Sentiment Analysis
ishan0019
 
Database Systems - Introduction (Chapter 1)
Database Systems - Introduction (Chapter 1)Database Systems - Introduction (Chapter 1)
Database Systems - Introduction (Chapter 1)
Vidyasagar Mundroy
 
Database an introduction
Database an introductionDatabase an introduction
Database an introduction
Anwarul Islam, PhD
 
Fanuc pmc programming manual
Fanuc pmc programming manualFanuc pmc programming manual
Fanuc pmc programming manual
Antonio J
 
Ppl for students unit 1,2 and 3
Ppl for students unit 1,2 and 3Ppl for students unit 1,2 and 3
Ppl for students unit 1,2 and 3
Akshay Nagpurkar
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
wafaa_A7
 
Chapter 6m
Chapter 6mChapter 6m
Chapter 6m
wafaa_A7
 
1 . introduction to communication system
1 . introduction to communication system1 . introduction to communication system
1 . introduction to communication system
abhijitjnec
 
Chapter 2 amplitude_modulation
Chapter 2 amplitude_modulationChapter 2 amplitude_modulation
Chapter 2 amplitude_modulation
Hattori Sidek
 
Digital communication viva questions
Digital communication viva questionsDigital communication viva questions
Digital communication viva questions
ishan0019
 
Introduction to programming using Visual Basic 6
Introduction to programming using Visual Basic 6Introduction to programming using Visual Basic 6
Introduction to programming using Visual Basic 6
Jeanie Arnoco
 
Unit 4
Unit 4Unit 4
Unit 5
Unit 5Unit 5
Unit 2 Principles of Programming Languages
Unit 2 Principles of Programming LanguagesUnit 2 Principles of Programming Languages
Unit 2 Principles of Programming Languages
Vasavi College of Engg
 
PULSE CODE MODULATION (PCM)
PULSE CODE MODULATION (PCM)PULSE CODE MODULATION (PCM)
PULSE CODE MODULATION (PCM)
vishnudharan11
 
Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming language
Vasavi College of Engg
 

Viewers also liked (20)

Computer programming language concept
Computer programming language conceptComputer programming language concept
Computer programming language concept
 
8150.graphs
8150.graphs8150.graphs
8150.graphs
 
Java practice programs for beginners
Java practice programs for beginnersJava practice programs for beginners
Java practice programs for beginners
 
introduction to database
 introduction to database introduction to database
introduction to database
 
Sentiment Analysis
Sentiment AnalysisSentiment Analysis
Sentiment Analysis
 
Database Systems - Introduction (Chapter 1)
Database Systems - Introduction (Chapter 1)Database Systems - Introduction (Chapter 1)
Database Systems - Introduction (Chapter 1)
 
Database an introduction
Database an introductionDatabase an introduction
Database an introduction
 
Fanuc pmc programming manual
Fanuc pmc programming manualFanuc pmc programming manual
Fanuc pmc programming manual
 
Ppl for students unit 1,2 and 3
Ppl for students unit 1,2 and 3Ppl for students unit 1,2 and 3
Ppl for students unit 1,2 and 3
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 
Chapter 6m
Chapter 6mChapter 6m
Chapter 6m
 
1 . introduction to communication system
1 . introduction to communication system1 . introduction to communication system
1 . introduction to communication system
 
Chapter 2 amplitude_modulation
Chapter 2 amplitude_modulationChapter 2 amplitude_modulation
Chapter 2 amplitude_modulation
 
Digital communication viva questions
Digital communication viva questionsDigital communication viva questions
Digital communication viva questions
 
Introduction to programming using Visual Basic 6
Introduction to programming using Visual Basic 6Introduction to programming using Visual Basic 6
Introduction to programming using Visual Basic 6
 
Unit 4
Unit 4Unit 4
Unit 4
 
Unit 5
Unit 5Unit 5
Unit 5
 
Unit 2 Principles of Programming Languages
Unit 2 Principles of Programming LanguagesUnit 2 Principles of Programming Languages
Unit 2 Principles of Programming Languages
 
PULSE CODE MODULATION (PCM)
PULSE CODE MODULATION (PCM)PULSE CODE MODULATION (PCM)
PULSE CODE MODULATION (PCM)
 
Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming language
 

Similar to CIS110 Computer Programming Design Chapter (3)

Logic Formulation 3
Logic Formulation 3Logic Formulation 3
Logic Formulation 3
deathful
 
CIS110 Computer Programming Design Chapter (5)
CIS110 Computer Programming Design Chapter  (5)CIS110 Computer Programming Design Chapter  (5)
CIS110 Computer Programming Design Chapter (5)
Dr. Ahmed Al Zaidy
 
CIS110 Computer Programming Design Chapter (2)
CIS110 Computer Programming Design Chapter  (2)CIS110 Computer Programming Design Chapter  (2)
CIS110 Computer Programming Design Chapter (2)
Dr. Ahmed Al Zaidy
 
CIS110 Computer Programming Design Chapter (4)
CIS110 Computer Programming Design Chapter  (4)CIS110 Computer Programming Design Chapter  (4)
CIS110 Computer Programming Design Chapter (4)
Dr. Ahmed Al Zaidy
 
5 software design
5 software design5 software design
5 software design
cherrybear2014
 
SE-software design.ppt
SE-software design.pptSE-software design.ppt
SE-software design.ppt
vishal choudhary
 
Week 6
Week 6Week 6
M.tech cse 10july13 (1)
M.tech cse  10july13 (1)M.tech cse  10july13 (1)
M.tech cse 10july13 (1)
vijay707070
 
clean architecture uncle bob AnalysisAndDesign.el.en.pptx
clean architecture uncle bob AnalysisAndDesign.el.en.pptxclean architecture uncle bob AnalysisAndDesign.el.en.pptx
clean architecture uncle bob AnalysisAndDesign.el.en.pptx
saber tabatabaee
 
Data Structures and Algorithm - Module 1.pptx
Data Structures and Algorithm - Module 1.pptxData Structures and Algorithm - Module 1.pptx
Data Structures and Algorithm - Module 1.pptx
EllenGrace9
 
lect 1-ds algo(final)_2.pdf
lect 1-ds  algo(final)_2.pdflect 1-ds  algo(final)_2.pdf
lect 1-ds algo(final)_2.pdf
MuhammadUmerIhtisham
 
RAJAT PROJECT.pptx
RAJAT PROJECT.pptxRAJAT PROJECT.pptx
RAJAT PROJECT.pptx
SayedMohdAsim2
 
Reading Notes : the practice of programming
Reading Notes : the practice of programmingReading Notes : the practice of programming
Reading Notes : the practice of programming
Juggernaut Liu
 
Algorithms and Flowcharts
Algorithms and FlowchartsAlgorithms and Flowcharts
Algorithms and Flowcharts
Lp Singh
 
CIS110 Computer Programming Design Chapter (13)
CIS110 Computer Programming Design Chapter  (13)CIS110 Computer Programming Design Chapter  (13)
CIS110 Computer Programming Design Chapter (13)
Dr. Ahmed Al Zaidy
 
Software Architectures, Week 2 - Decomposition techniques
Software Architectures, Week 2 - Decomposition techniquesSoftware Architectures, Week 2 - Decomposition techniques
Software Architectures, Week 2 - Decomposition techniques
Angelos Kapsimanis
 
COM1407: Structured Program Development
COM1407: Structured Program Development COM1407: Structured Program Development
COM1407: Structured Program Development
Hemantha Kulathilake
 
A Survey of Machine Learning Methods Applied to Computer ...
A Survey of Machine Learning Methods Applied to Computer ...A Survey of Machine Learning Methods Applied to Computer ...
A Survey of Machine Learning Methods Applied to Computer ...
butest
 
vb research
vb researchvb research
vb research
Isma Pokharel
 
test.pptx
test.pptxtest.pptx
test.pptx
Stacia7
 

Similar to CIS110 Computer Programming Design Chapter (3) (20)

Logic Formulation 3
Logic Formulation 3Logic Formulation 3
Logic Formulation 3
 
CIS110 Computer Programming Design Chapter (5)
CIS110 Computer Programming Design Chapter  (5)CIS110 Computer Programming Design Chapter  (5)
CIS110 Computer Programming Design Chapter (5)
 
CIS110 Computer Programming Design Chapter (2)
CIS110 Computer Programming Design Chapter  (2)CIS110 Computer Programming Design Chapter  (2)
CIS110 Computer Programming Design Chapter (2)
 
CIS110 Computer Programming Design Chapter (4)
CIS110 Computer Programming Design Chapter  (4)CIS110 Computer Programming Design Chapter  (4)
CIS110 Computer Programming Design Chapter (4)
 
5 software design
5 software design5 software design
5 software design
 
SE-software design.ppt
SE-software design.pptSE-software design.ppt
SE-software design.ppt
 
Week 6
Week 6Week 6
Week 6
 
M.tech cse 10july13 (1)
M.tech cse  10july13 (1)M.tech cse  10july13 (1)
M.tech cse 10july13 (1)
 
clean architecture uncle bob AnalysisAndDesign.el.en.pptx
clean architecture uncle bob AnalysisAndDesign.el.en.pptxclean architecture uncle bob AnalysisAndDesign.el.en.pptx
clean architecture uncle bob AnalysisAndDesign.el.en.pptx
 
Data Structures and Algorithm - Module 1.pptx
Data Structures and Algorithm - Module 1.pptxData Structures and Algorithm - Module 1.pptx
Data Structures and Algorithm - Module 1.pptx
 
lect 1-ds algo(final)_2.pdf
lect 1-ds  algo(final)_2.pdflect 1-ds  algo(final)_2.pdf
lect 1-ds algo(final)_2.pdf
 
RAJAT PROJECT.pptx
RAJAT PROJECT.pptxRAJAT PROJECT.pptx
RAJAT PROJECT.pptx
 
Reading Notes : the practice of programming
Reading Notes : the practice of programmingReading Notes : the practice of programming
Reading Notes : the practice of programming
 
Algorithms and Flowcharts
Algorithms and FlowchartsAlgorithms and Flowcharts
Algorithms and Flowcharts
 
CIS110 Computer Programming Design Chapter (13)
CIS110 Computer Programming Design Chapter  (13)CIS110 Computer Programming Design Chapter  (13)
CIS110 Computer Programming Design Chapter (13)
 
Software Architectures, Week 2 - Decomposition techniques
Software Architectures, Week 2 - Decomposition techniquesSoftware Architectures, Week 2 - Decomposition techniques
Software Architectures, Week 2 - Decomposition techniques
 
COM1407: Structured Program Development
COM1407: Structured Program Development COM1407: Structured Program Development
COM1407: Structured Program Development
 
A Survey of Machine Learning Methods Applied to Computer ...
A Survey of Machine Learning Methods Applied to Computer ...A Survey of Machine Learning Methods Applied to Computer ...
A Survey of Machine Learning Methods Applied to Computer ...
 
vb research
vb researchvb research
vb research
 
test.pptx
test.pptxtest.pptx
test.pptx
 

More from Dr. Ahmed Al Zaidy

Chapter 14 Exploring Object-based Programming
Chapter 14 Exploring Object-based ProgrammingChapter 14 Exploring Object-based Programming
Chapter 14 Exploring Object-based Programming
Dr. Ahmed Al Zaidy
 
Chapter 13 Programming for web forms
Chapter 13 Programming for web formsChapter 13 Programming for web forms
Chapter 13 Programming for web forms
Dr. Ahmed Al Zaidy
 
Chapter 12 Working with Document nodes and style sheets
Chapter 12 Working with Document nodes and style sheetsChapter 12 Working with Document nodes and style sheets
Chapter 12 Working with Document nodes and style sheets
Dr. Ahmed Al Zaidy
 
Chapter 11 Working with Events and Styles
Chapter 11 Working with Events and StylesChapter 11 Working with Events and Styles
Chapter 11 Working with Events and Styles
Dr. Ahmed Al Zaidy
 
Chapter 10 Exploring arrays, loops, and conditional statements
Chapter 10 Exploring arrays, loops, and conditional statementsChapter 10 Exploring arrays, loops, and conditional statements
Chapter 10 Exploring arrays, loops, and conditional statements
Dr. Ahmed Al Zaidy
 
Chapter 9 Getting Started with JavaScript
Chapter 9 Getting Started with JavaScriptChapter 9 Getting Started with JavaScript
Chapter 9 Getting Started with JavaScript
Dr. Ahmed Al Zaidy
 
Chapter 8 Enhancing a website with multimedia
Chapter 8 Enhancing a website with multimediaChapter 8 Enhancing a website with multimedia
Chapter 8 Enhancing a website with multimedia
Dr. Ahmed Al Zaidy
 
Chapter 7 Designing a web form
Chapter 7 Designing a web formChapter 7 Designing a web form
Chapter 7 Designing a web form
Dr. Ahmed Al Zaidy
 
Chapter 6 Working with Tables and Columns
Chapter 6 Working with Tables and ColumnsChapter 6 Working with Tables and Columns
Chapter 6 Working with Tables and Columns
Dr. Ahmed Al Zaidy
 
Chapter 5 Designing for the mobile web
Chapter 5 Designing for the mobile webChapter 5 Designing for the mobile web
Chapter 5 Designing for the mobile web
Dr. Ahmed Al Zaidy
 
Chapter 4 Graphic Design with CSS
Chapter 4 Graphic Design with CSSChapter 4 Graphic Design with CSS
Chapter 4 Graphic Design with CSS
Dr. Ahmed Al Zaidy
 
Chapter 3 Designing a Page Layout
Chapter 3 Designing a Page LayoutChapter 3 Designing a Page Layout
Chapter 3 Designing a Page Layout
Dr. Ahmed Al Zaidy
 
Chapter 2 Getting Started with CSS
Chapter 2 Getting Started with CSSChapter 2 Getting Started with CSS
Chapter 2 Getting Started with CSS
Dr. Ahmed Al Zaidy
 
Chapter 1 Getting Started with HTML5
Chapter 1 Getting Started with HTML5Chapter 1 Getting Started with HTML5
Chapter 1 Getting Started with HTML5
Dr. Ahmed Al Zaidy
 
Integer overflows
Integer overflowsInteger overflows
Integer overflows
Dr. Ahmed Al Zaidy
 
testing throughout-the-software-life-cycle-section-2
testing throughout-the-software-life-cycle-section-2testing throughout-the-software-life-cycle-section-2
testing throughout-the-software-life-cycle-section-2
Dr. Ahmed Al Zaidy
 
Fundamental of testing
Fundamental of testingFundamental of testing
Fundamental of testing
Dr. Ahmed Al Zaidy
 
Chapter 15 Risk Mitigation
Chapter 15 Risk MitigationChapter 15 Risk Mitigation
Chapter 15 Risk Mitigation
Dr. Ahmed Al Zaidy
 
Chapter 14 Business Continuity
Chapter 14 Business ContinuityChapter 14 Business Continuity
Chapter 14 Business Continuity
Dr. Ahmed Al Zaidy
 
Chapter 13 Vulnerability Assessment and Data Security
Chapter 13 Vulnerability Assessment and Data SecurityChapter 13 Vulnerability Assessment and Data Security
Chapter 13 Vulnerability Assessment and Data Security
Dr. Ahmed Al Zaidy
 

More from Dr. Ahmed Al Zaidy (20)

Chapter 14 Exploring Object-based Programming
Chapter 14 Exploring Object-based ProgrammingChapter 14 Exploring Object-based Programming
Chapter 14 Exploring Object-based Programming
 
Chapter 13 Programming for web forms
Chapter 13 Programming for web formsChapter 13 Programming for web forms
Chapter 13 Programming for web forms
 
Chapter 12 Working with Document nodes and style sheets
Chapter 12 Working with Document nodes and style sheetsChapter 12 Working with Document nodes and style sheets
Chapter 12 Working with Document nodes and style sheets
 
Chapter 11 Working with Events and Styles
Chapter 11 Working with Events and StylesChapter 11 Working with Events and Styles
Chapter 11 Working with Events and Styles
 
Chapter 10 Exploring arrays, loops, and conditional statements
Chapter 10 Exploring arrays, loops, and conditional statementsChapter 10 Exploring arrays, loops, and conditional statements
Chapter 10 Exploring arrays, loops, and conditional statements
 
Chapter 9 Getting Started with JavaScript
Chapter 9 Getting Started with JavaScriptChapter 9 Getting Started with JavaScript
Chapter 9 Getting Started with JavaScript
 
Chapter 8 Enhancing a website with multimedia
Chapter 8 Enhancing a website with multimediaChapter 8 Enhancing a website with multimedia
Chapter 8 Enhancing a website with multimedia
 
Chapter 7 Designing a web form
Chapter 7 Designing a web formChapter 7 Designing a web form
Chapter 7 Designing a web form
 
Chapter 6 Working with Tables and Columns
Chapter 6 Working with Tables and ColumnsChapter 6 Working with Tables and Columns
Chapter 6 Working with Tables and Columns
 
Chapter 5 Designing for the mobile web
Chapter 5 Designing for the mobile webChapter 5 Designing for the mobile web
Chapter 5 Designing for the mobile web
 
Chapter 4 Graphic Design with CSS
Chapter 4 Graphic Design with CSSChapter 4 Graphic Design with CSS
Chapter 4 Graphic Design with CSS
 
Chapter 3 Designing a Page Layout
Chapter 3 Designing a Page LayoutChapter 3 Designing a Page Layout
Chapter 3 Designing a Page Layout
 
Chapter 2 Getting Started with CSS
Chapter 2 Getting Started with CSSChapter 2 Getting Started with CSS
Chapter 2 Getting Started with CSS
 
Chapter 1 Getting Started with HTML5
Chapter 1 Getting Started with HTML5Chapter 1 Getting Started with HTML5
Chapter 1 Getting Started with HTML5
 
Integer overflows
Integer overflowsInteger overflows
Integer overflows
 
testing throughout-the-software-life-cycle-section-2
testing throughout-the-software-life-cycle-section-2testing throughout-the-software-life-cycle-section-2
testing throughout-the-software-life-cycle-section-2
 
Fundamental of testing
Fundamental of testingFundamental of testing
Fundamental of testing
 
Chapter 15 Risk Mitigation
Chapter 15 Risk MitigationChapter 15 Risk Mitigation
Chapter 15 Risk Mitigation
 
Chapter 14 Business Continuity
Chapter 14 Business ContinuityChapter 14 Business Continuity
Chapter 14 Business Continuity
 
Chapter 13 Vulnerability Assessment and Data Security
Chapter 13 Vulnerability Assessment and Data SecurityChapter 13 Vulnerability Assessment and Data Security
Chapter 13 Vulnerability Assessment and Data Security
 

Recently uploaded

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
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
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
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
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
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
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
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
What is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptxWhat is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptx
christianmathematics
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
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
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
ArianaBusciglio
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
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
 

Recently uploaded (20)

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
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.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
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
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...
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
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...
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
What is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptxWhat is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptx
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
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
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
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)
 

CIS110 Computer Programming Design Chapter (3)

  • 1. Programming Logic and Design Eighth Edition Chapter 3 Understanding Structure
  • 2. Objectives In this chapter, you will learn about: • The disadvantages of unstructured spaghetti code • The three basic structures—sequence, selection, and loop • Using a priming input to structure a program • The need for structure • Recognizing structure • Structuring and modularizing unstructured logic 2Programming Logic and Design, Eighth Edition
  • 3. The Disadvantages of Unstructured Spaghetti Code • Spaghetti code – Logically snarled program statements – Often a complicated mess – Programs often work but are difficult to read and maintain – Confusing and prone to error • Unstructured programs – Do not follow the rules of structured logic • Structured programs – Follow the rules of structured logic 3Programming Logic and Design, Eighth Edition
  • 4. 4Programming Logic and Design, Eighth Edition Figure 3-1 Spaghetti code logic for washing a dog
  • 5. Understanding the Three Basic Structures • Structure – Basic unit of programming logic – Sequence structure • Perform actions or tasks in order • No branching or skipping any task – Selection structure (decision structure) • Ask a question, take one of two actions • Often called if-then-else • Dual-alternative ifs or single-alternative ifs – Loop structure • Repeat actions while a condition remains true 5Programming Logic and Design, Eighth Edition
  • 6. Understanding the Three Basic Structures (continued) 6Programming Logic and Design, Eighth Edition Figure 3-2 Sequence structure
  • 7. Understanding the Three Basic Structures (continued) 7Programming Logic and Design, Eighth Edition Figure 3-3 Selection structure
  • 8. Understanding the Three Basic Structures (continued) • Dual-alternative ifs – Contains two alternatives – The if-then-else structure 8Programming Logic and Design, Eighth Edition if someCondition is true then do oneProcess else do theOtherProcess endif
  • 9. Understanding the Three Basic Structures (continued) • Single-alternative ifs – An else clause is not required • null case – Situation where nothing is done 9Programming Logic and Design, Eighth Edition if employee belongs to dentalPlan then deduct $40 from employeeGrossPay
  • 10. Understanding the Three Basic Structures (continued) 10Programming Logic and Design, Eighth Edition Figure 3-4 Single-alternative selection structure
  • 11. Understanding the Three Basic Structures (continued) • Loop structure – Repeats a set of actions while a condition remains true • Loop body – Also called repetition or iteration – Condition is tested first in the most common form of loop – The while…do or while loop 11Programming Logic and Design, Eighth Edition
  • 12. Understanding the Three Basic Structures (continued) 12Programming Logic and Design, Eighth Edition Figure 3-5 Loop structure
  • 13. Understanding the Three Basic Structures (continued) • Loop structure 13Programming Logic and Design, Eighth Edition while testCondition continues to be true do someProcess endwhile while you continue to be hungry take another bite of food determine if you still feel hungry endwhile
  • 14. Understanding the Three Basic Structures (continued) • All logic problems can be solved using only sequence, selection, and loop • Structures can be combined in an infinite number of ways • Stacking structures – Attaching structures end-to-end • End-structure statement – Indicates the end of a structure – The endif statement ends an if-then-else structure – The endwhile statement ends a loop structure 14Programming Logic and Design, Eighth Edition
  • 15. Understanding the Three Basic Structures (continued) 15Programming Logic and Design, Eighth Edition Figure 3-6 Structured flowchart and pseudocode with three stacked structures
  • 16. Understanding the Three Basic Structures (continued) • Any individual task or step in a structure can be replaced by a structure • Nesting structures – Placing one structure within another – Indent the nested structure’s statements • Block – A group of statements that execute as a single unit 16Programming Logic and Design, Eighth Edition
  • 17. Understanding the Three Basic Structures (continued) 17Programming Logic and Design, Eighth Edition Figure 3-7 Flowchart and pseudocode showing nested structures— a sequence nested within a selection
  • 18. Understanding the Three Basic Structures (continued) 18Programming Logic and Design, Eighth Edition Figure 3-8 Flowchart and pseudocode showing nested structures— a loop nested within a sequence, nested within a selection
  • 19. Understanding the Three Basic Structures (continued) 19Programming Logic and Design, Eighth Edition Figure 3-9 Flowchart and pseudocode for a selection within a loop within a sequence within a selection
  • 20. Understanding the Three Basic Structures (continued) • Structured programs have the following characteristics: – Include only combinations of the three basic structures – Each structure 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 20Programming Logic and Design, Eighth Edition
  • 21. Using a Priming Input to Structure a Program • Priming input (or priming read) – Reads the first input data record – Is outside the loop that reads the rest of the records – Helps keep the program structured • Analyze a flowchart for structure one step at a time • Watch for unstructured loops that do not follow this order – First ask a question – Take action based on the answer – Return to ask the question again 21Programming Logic and Design, Eighth Edition
  • 22. Using a Priming Input to Structure a Program (continued) 22Programming Logic and Design, Eighth Edition Figure 3-14 Structured, but nonfunctional, flowchart of number-doubling problem
  • 23. Using a Priming Input to Structure a Program (continued) 23Programming Logic and Design, Eighth Edition Figure 3-15 Functional but unstructured flowchart
  • 24. 24Programming Logic and Design, Eighth Edition Figure 3-16 Functional, structured flowchart for the number-doubling problem
  • 25. 25Programming Logic and Design, Eighth Edition Figure 3-17 Structured but incorrect solution to the number-doubling problem
  • 26. Understanding the Reasons for Structure • Clarity—unstructured programs are confusing • Professionalism—other programmers expect it • Efficiency—most languages support it • Maintenance —other programmers find it easier to read • Modularity —easily broken down into modules 26Programming Logic and Design, Eighth Edition
  • 27. 27Programming Logic and Design, Eighth Edition Figure 3-18 Example 1 Structured Flowcharts? Recognizing Structure Figure 3-19 Example 2
  • 28. Recognizing Structure (continued) 28Programming Logic and Design, Eighth Edition Figure 3-20 Example 3 An Unstructured Flowchart
  • 29. 29Programming Logic and Design, Eighth Edition Figure 3-21 Steps to structure the dog- washing process Recognizing Structure (continued)
  • 30. 30Programming Logic and Design, Eighth Edition Figure 3-22 Structured dog-washing flowchart and pseudocode Recognizing Structure (continued)
  • 31. 31Programming Logic and Design, Eighth Edition Figure 3-23 Modularized version of the dog-washing program Recognizing Structure (continued)
  • 32. Summary • Spaghetti code – Statements that do not follow rules of structured logic • Three basic structures – Sequence, selection, and loop – Combined by stacking and nesting • Priming input – Statement that reads the first input value prior to starting a structured loop 32Programming Logic and Design, Eighth Edition
  • 33. Summary (continued) • Structured techniques promote: – Clarity – Professionalism – Efficiency – Modularity • Flowcharts can be made structured by untangling • Logical steps can be rewritten to conform to the three structures 33Programming Logic and Design, Eighth Edition