Programming instructions

Reference
Project Lead The Way
©
and Carnegie Mellon Robotics Academy
©
/ For use with VEX
®
Robotics Systems
Pseudo Code & Flow Charts 1
Pseudocode is a shorthand notation for programming which uses a combination of informal
programming structures and verbal descriptions of code. Emphasis is placed on expressing
the behavior or outcome of each portion of code rather than on strictly correct syntax (it does
still need to be reasonable, though).
In general, pseudocode is used to outline a program before translating it into proper syntax.
This helps in the initial planning of a program, by creating the logical framework and
sequence of the code. An additional benet is that because pseudocode does not need
to use a specic syntax, it can be translated into different programming languages and is
therefore somewhat universal. It captures the logic and ow of a solution without the bulk of
strict syntax rules.
Below is some pseudocode written for a program which controls a motor and an LED as
long as a touch sensor is not pressed. A motor turns on and an LED turns off if no object is
deteced within 20cm of a sonar sensor; the motor turns off and an LED turns on if an object
is detected within 20 cm.
Pseudocode & Flow Charts
task main()
{
while ( touch sensor is not pressed )
{
if(sonar detects object > 20cm away)
{
Right Motor runs forward
Red LED turns off
}
else
{
Right Motor stops
Red LED turns on
}
}
}
Some intact syntax
The use of a while loop
in the pseudocode is tting
because the way we read a
while loop is very similar to
the manner in which it
is used in the program.
This pseudocode example includes elements of both programming language, and the English
language. Curly braces are used as a visual aid for where portions of code need to be placed
when they are nally written out in full and proper syntax.
Descriptions
There are no actual motor
commands in this section of
the code, but the pseudocode
suggests where the
commands belong and what
they need
to accomplish.
Go to Reference Links