Previous page Next page Navigation bar

Calculator Programming Tutorial

Programming Building Blocks I

Control Flow I

Structure Composition

Any program can be written with sequencing, alternatives, and pre-tested loops. However, this statement does not merely refer to stringing these control structures along, one after the other. Each of these control structures can be embedded in the others. This embedding, or composition, of control structures is also necessary.

Composing control structures is wrapping one around another. Each of the three constructs we have seen so far has a single entry point, and a single exit point. Each of the three constructs also has component processing pieces — each with a single entry point, and a single exit point. Therefore, each of these constructs can be used as a component of a larger construct. We have already seen alternatives nested inside alternatives, which yielded an overall structure like this:

Flowchart of nested alternatives; click for description

We might have a loop as one of the branches of an alternative, as follows:

Flowchart of loop nested in alternative; click for description

We might have sequences and an alternative in the body of a loop, as follows:

Flowchart of alternative nested in loop; click for description

In each of these cases, the single entry/single exit criterion allows the construct to be thought of as a single conceptual unit. In terms of overall function, a single processing box can replace any single entry/single exit construct. This permits thinking of the flowchart, and so the program, at a variety of levels. This is illustrated in the series of flowcharts below: each circled construct is condensed into a single shaded processing block:

Sequence of flowcharts simplifying; click for description

This also means we can reverse the process, and decompose an overall process into constituent pieces. Any single processing block can be further refined into a single entry/single exit construct. This is illustrated in the series of flowcharts below: each single shaded processing block is elaborated into a circled single entry/single exit construct:

Sequence of flowcharts becoming more elaborated; click for description

This process of repeated decomposition, or successive refinement, is the fundamental approach in much of programming. After all, usually we have a problem, and the goal is to refine the single box, “solve the problem,” into a series of series of constructs that we can program.

[ Previous page | Top of page | Next page ]

Previous page Top of page Next page Navigation bar

Copyright © 2002 Brian Hetrick
Page last updated 13 January 2002.

Brian’s Casio Calculator Corner

Home

Programs

Tutorial

Preface

Introduction

Fundamentals

Building Blocks I

Introduction

Comments

Data Types

Numbers

Variables

Expressions

Control Flow I

Introduction

Sequences

Alternatives

Loops

Composition

Control Flow II

Subprograms

Basic I/O

Algorithms

A First Program

Examples

Exercises

Answers

Modularization

Data Structures I

Recursion

Program Attributes

Building Blocks II

Algorithm Analysis

Structuring

Data Structures II

Abstract Types

Objects

Problem Analysis

Reference Card

References

Puzzles

Site Information

Your Privacy

Site Map

E-mail

Site Technical Data