An Introduction to Control Structures - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

An Introduction to Control Structures

Description:

These structures are called control structures or logic structures, because they ... when the balloon is red in this case, drop the balloon in the red box and the ... – PowerPoint PPT presentation

Number of Views:60
Avg rating:3.0/5.0
Slides: 14
Provided by: informat997
Learn more at: https://www.kean.edu
Category:

less

Transcript and Presenter's Notes

Title: An Introduction to Control Structures


1
An Introduction to Control Structures
2
Objectives
  • After completing this overview, you will be able
    to
  • Explain the sequence, selection, and repetition
    structures
  • Write simple algorithms using the sequence,
    selection, and repetition structures

3
Defining Control Structures
  • All computer programs, no matter how simple or
    how complex, are written using one or more of
    three basic structures
  • Sequence Selection
  • Repetition
  • These structures are called control structures or
    logic structures, because they control the flow
    of a programs logic
  • In most programs, you will use both the selection
    and repetition structures

4
The Sequence Structure
  • The sequence structure in a computer program
    directs the computer to process the program
    instructions, one after another, in the order
    listed in the program
  • You can observe how the sequence structure works
    by programming a mechanical man named Rob
  • Like a computer, Rob has a limited instruction
    setin other words, Rob can understand only a
    specific number of instructions, also called
    commands

5
The Sequence Structure
  • The four instructions shown in Figure 1-1 are
    called an algorithm
  • An algorithm is simply the set of step-by-step
    instructions that accomplish a task

6
The Repetition Structure
  • When used in a program, the repetition structure,
    also referred to as a loop, directs the computer
    to repeat one or more instructions until some
    condition is met, at which time the computer
    should stop repeating the instructions
  • Notice that the algorithm contains both the
    sequence and repetition structures
  • Rather than writing the walk instruction 50
    times, this algorithm uses the repeat 50 times
    instruction to direct Rob to walk 50 times before
    he turns and then sits

7
The Repetition Structure
  • Notice that the instruction to be repeatedin
    this case, walkis indented below the repeat50
    timesinstruction
  • Indenting in this manner indicates the
    instructions that are part of the repetition
    structure, and therefore, are to be repeated

8
The Repetition Structure
  • But what if you do not know precisely how many
    steps there are between Rob and the chair?
  • You simply must change the repetition structures
    condition
  • The repetition structure shown in the algorithm
    in Figure 1-3 ends when Rob is standing
    directly in front of the chair

9
The Selection Structure
  • Like the sequence and repetition structures, you
    already are familiar with the selection
    structure, also called the decision structure
  • The selection structure makes a decision, and
    then takes an appropriate action based on that
    decision
  • The selection structure also provides the
    appropriate action to take based on the result of
    that decision

10
Robs New Instruction Set
  • Notice that the instructions to be followed when
    the balloon is redin this case, drop the balloon
    in the red boxand the instruction to be followed
    when the balloon is not redin this case, drop
    the balloon in the yellow boxare indented

11
An Example of the Selection Structure
  • Notice that the algorithm shown in Figure 1-5
    contains all three control structures sequence,
    selection, and repetition

12
Summary Concept Lesson
  • An algorithm is the set of step-by-step
    instructions that solve a problem
  • The algorithms for all computer programs contain
    one or more of the following three control
    structures sequence, selection, and repetition
  • The sequence structure directs the computer to
    process the instructions, one after another, in
    the order listed in the program

13
Summary Concept Lesson
  • The repetition structure directs the computer to
    repeat one or more instructions until some
    condition is met
  • The selection structure, also called the decision
    structure, directs the computer to make a
    decision, and then selects an appropriate action
    to take based on that decision
  • The sequence structure is used in all programs
  • Most programs also contain both the selection and
    repetition structures
Write a Comment
User Comments (0)
About PowerShow.com