COSC 1315

Programming Fundamentals

The Sequence Structure

Revised:  January 27, 2007
By Richard G. Baldwin

File:  Pf00107.htm
Practice Text


This lesson was written specifically for the benefit of my students in COSC 1315, Fundamentals of Programming.  The lesson was written under the assumption that those students have no prior programming knowledge when they enroll in the course.

Another browser window

I recommend that you open another copy of this document in a separate browser window so that you can view the code and the discussion of that code at the same time.


A simple C++ program

This is a very simple C++ program that illustrates the sequence structure.  The main function for this program contains a simple sequence of four statements, each of which displays one line of text on the screen.

In computer programming, we often group the following three terms together:

However, the program that I will explain in this lesson does not include a selection (decision) structure.  It also does not include a loop (iteration) structure.

(I will explain selection and loop structures in a future lesson.)

The output

The program displays the following four lines of text on the screen:

Hello Viet Nam
Hello Iraq
Hello America
Hello World

Sample Program

You learned about all of the programming elements contained in the following program in Lesson 105.  Therefore, the only thing that is new about this program is the sequential organizational structure.  That organizational structure is almost trivial, consisting simply of a sequence of four statements that cause four lines of text to be displayed on the computer screen.

/*File:  Sequence01.cpp

This is a very simple C++ program.  It 
illustrates the sequence structure.  It does not
include a decision/selection structure.  It
also does not include a loop/iteration 

This program displays the following text on the 

Hello Viet Nam
Hello Iraq
Hello America
Hello World


#include <iostream>
using namespace std;

int main(){//Global main function.
  //This main function executes a sequence of
  // statements and then terminates.  The
  // statements in the sequence do not
  // include decisions or loops.
  cout << "Hello Viet Nam\n";
  cout << "Hello Iraq\n";
  cout << "Hello America\n";
  cout << "Hello World\n";
  return 0;
}//end main function

Listing 1

Copyright 2005, Richard G. Baldwin.  Reproduction in whole or in part in any form or medium without express written permission from Richard Baldwin is prohibited.

About the author

Richard Baldwin is a college professor (at Austin Community College in Austin, TX) and private consultant whose primary focus is a combination of Java, C#, and XML. In addition to the many platform and/or language independent benefits of Java and C# applications, he believes that a combination of Java, C#, and XML will become the primary driving force in the delivery of structured information on the Web.

Richard has participated in numerous consulting projects and he frequently provides onsite training at the high-tech companies located in and around Austin, Texas.  He is the author of Baldwin's Programming Tutorials, which have gained a worldwide following among experienced and aspiring programmers. He has also published articles in JavaPro magazine.

In addition to his programming expertise, Richard has many years of practical experience in Digital Signal Processing (DSP).  His first job after he earned his Bachelor's degree was doing DSP in the Seismic Research Department of Texas Instruments.  (TI is still a world leader in DSP.)  In the following years, he applied his programming and DSP expertise to other interesting areas including sonar and underwater acoustics.

Richard holds an MSEE degree from Southern Methodist University and has many years of experience in the application of computer technology to real-world problems.