0% found this document useful (0 votes)
8 views12 pages

The Five Program Steps

The document describes the five steps of a typical computer program: 1) Initialization step to prepare the environment for program execution 2) Input step to acquire needed information 3) Process step to process inputs and generate new data 4) Output step to display or pass on the results 5) Termination step to gracefully end the program It provides examples using a fire alarm program to illustrate each step.

Uploaded by

albert aintstine
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views12 pages

The Five Program Steps

The document describes the five steps of a typical computer program: 1) Initialization step to prepare the environment for program execution 2) Input step to acquire needed information 3) Process step to process inputs and generate new data 4) Output step to display or pass on the results 5) Termination step to gracefully end the program It provides examples using a fire alarm program to illustrate each step.

Uploaded by

albert aintstine
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

The Five Program

Steps
1. Initialization Step
The purpose of the Initialization Step is to establish the environment in
which the program will run.
The Initialization Step does whatever background preparation must be
done before the program can begin execution to solve its primary task.
2. Input Step
Almost every computer program has a task that is designed to take
some existing state of information, process it in some way, and show the new
state of that information.
The Input Step is the sequence of program statements that are
necessary to acquire the information needed to solve the task at hand.

Example:

If you are writing a fire alarm system, then you take the
information provided by the fire sensors, interpret their current state and, if
there is a fire, do something about it. If the sensor shows no fire, then
perhaps a second set of sensors is read and the process is repeated.
Indeed, your program may do nothing for decades but take new readings
every few seconds and determine whether some remedial action is
necessary.
3. Process Step
Process Step is responsible for taking a set of inputs and processing it to
get a new set of data.
Note that a program may have multiple Process Steps.
Example:
Continuing with our fire alarm program, once
the input from the sensors is received, some body of
code must be responsible for determining whether the
sensors are detecting a fire. In other words, the voltage
(i.e., temperature) must be read (input) and then
interpreted (i.e., the data processed) to determine the
current state of the sensors.
4. Output Step
After the Process Step has finished its work, the new value is typically output on some
display device.
The Output Step is responsible for using the results of the Process Step. This utilization
could be as simple as displaying the new data on a display device or passing that new value on
to some other program.

Example:
In our fire alarm example, the Output Step
may cause an LED for a particular sensor to continue to
display a green color under normal conditions. If a fire is
sensed, perhaps the LED displays red or display some
text like " "Flame detected...! Take action immediately.",
so whomever is in charge can see what area of the
building is on fire.
5. Termination Step
The Termination Step has the responsibility of “cleaning up” after the program is
finished performing its task.
Termination Process should allow for a graceful termination of the currently running
program. However, many automated program are not designed to terminate.

Example:
A fire alarm system is likely designed to
continue running forever, as long as things are “normal.”
No
Even then, however, there may still be a Termination
Process that is followed. For example, if the fire alarm termination
system has a component failure, then the Termination some code.
Process may try to identify the failed component before
the system shuts down for repairs. Perhaps the
Termination Process deactivates the alarm system before
a maintenance shutdown.
Revisit to the Blink Program
If you look closely at the two lines
immediately above, you will see that none of
the lines ends with a semicolon. That is,
none of the lines forms a C program
statement because all program C
statements must end with a semicolon. If
that is the case, what are they and why are
they part of the source code?

The lines are called comment lines.


Comment lines are used to document what
is going on in a
program for whomever may be reading the
code. There are two basic types of
comments: (1) single-line and (2) multiline
comments.
Revisit to the Blink Program
Single-Line Comments
Single-line comments begin with a pair of slash (//)
characters. There can be no spaces between the two
slashes. (Otherwise the compiler might think it was looking
at the division operator.) Upon seeing the two
slash characters, the compiler knows that what follows
from the two slashes to the end of the current line is a
program comment and does not need to be compiled. As
such, comments that begin with // must appear on the
same line as the two slash characters. If you fold a
comment to the next line without the leading slashes, then
it will be seen as a syntax error by the compiler.

Again, an example of this type of comment is:

// Pin 13 has an LED connected on most Arduino boards.


// give it a name:
Revisit to the Blink Program

Multiline Comments
Multiline comments begin with a slash-
asterisk pair (/*) and end with an asterisk-
slash pair (*/). There are no spaces between
the two characters pairs. Everything in
between these two-character pairs is treated
as a comment and is ignored by the
compiler. Unlike single line comments,
multiline comments can span multiple lines.
Revisit to the Blink Program

Data Definition
The next line in the program is:
int led = 13;

The statement defines an integer data type


variable with the name led. The assignment
operator also
tells us that the program initializes the value
of led to 13. This means that our program
now has an integer
variable named led with the numeric value
13.
Revisit to the Blink Program
The setup() Function
The next several lines of code are reproduced here:

// the setup routine runs once when you press reset:


void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}

The code presents a short comment telling the


reader that the setup() function is called once when
you reset the program. This is a characteristic of all
Arduino C programs. Every program you write will
have a setup() function in it. Indeed, setup() marks
the starting point for all Arduino C programs. Where
Standard C always starts program execution with a
function named main(), it is setup() that marks the
program’s starting point in Arduino C.
Because setup() is the starting point for all Arduino C
programs, it also becomes the Initialization
Step in our Five Program Steps.
Revisit to the Blink Program
The loop() Function

After the setup() function completes its work, every


Arduino C program automatically calls the loop()
function. Stated differently, when the Initialization
Step (Step 1) is completed via the function call to
setup(), we are ready for Step 2, the Input Step. The
code for the loop() function is reproduced below:

// the loop routine runs over and over again forever:


void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is
the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making
the voltage LOW
delay(1000); // wait for a second
}

You might also like