Programming instructions

Reference
Project Lead The Way
©
and Carnegie Mellon Robotics Academy
©
/ For use with VEX
®
Robotics Systems
White Space 1
White Space with Natural Language
Program Without White Space
task main()
{
startMotor(armMotor, 63);
untilTouch(bumper);
stopMotor(armMotor);
wait(2.0);
startMotor(armMotor, 63);
untilRelease(bumper);
stopMotor(armMotor);
}
Both programs will perform the same, however, the second uses white space to organize the
code to separate the program’s two main behaviors: moving the arm up and moving the arm
down. In this case, line breaks (returns) were used to vertically segment the tasks.
Horizontal white space characters like spaces and tabs are also important. Below, white
space is used in the form of indentations to indicate which lines are within which control
structures (task main, while loop, if-else statement).
White Space is the use of spaces, tabs, and blank lines to visually organize code. Programmers
use White Space since it can group code into sensible, readable chunks without affecting how the
code is read by a machine. For example, a program that moves an arm up until a touch sensor is
pressed, stops, waits for 2 seconds, and then moves down until the touch sensor is released could
look like either of these:
task main()
{
startMotor(armMotor, 63);
untilTouch(bumper);
stopMotor(armMotor);
wait(2.0);
startMotor(armMotor, 63);
untilRelease(bumper);
stopMotor(armMotor);
}
Program With White Space
Program Without White Space
task main()
{
while(true)
{
if(SensorValue(touch)==0)
{
startMotor(armMotor, 63);
}
else
{
startMotor(armMotor, -63);
}
}
}
Program With White Space
task main()
{
while(true)
{
if(SensorValue(touch)==0)
{
startMotor(armMotor, 63);
}
else
{
startMotor(armMotor, -63);
}
}
}
Go to Reference Links