Elmo HARmonica, HARSFEN0602 software manual Program Flow Commands, Example

Models: HARmonica HARSFEN0602

1 220
Download 220 pages 51.63 Kb
Page 36
Image 36

HARSFEN0602ElmoHARmonicaSoftwareManual

PRELIMINARYDRAFT

Comments are texts that

written into the code to enhance its readability. There are three methods to write

comments.

 

 

A double asterisk marks comments. The comment starts in a double asterisk comment marker, and

terminates at the next end

line.

 

The Amplifier ignores the comments when running a program or evaluating an expression.

Example:

**my first program PX=1

**um=5

mo=1; **motor on

In the above example program, the first line is a comment used to enhance program readability. The comment terminates at the next end of line, so the next PX=1 instruction shall be compiled and executed. In the third line, the comment mark tells the Amplifier to ignore the UM=5 command. This technique is useful for temporarily masking program lines in the process of debugging.

The last line demonstrates that a comment may start anywhere in the program line. The MO=1 instruction preceding the comment marker shall be compiled and executed.

A percent sign (the MATLAB style) marks comments in the same way as a double asterisk. The comment starts in a percent sign comment marker, and terminates at the next end of line.

Example:

%my first program PX=1

%um=5

mo=1; %motor on

In this example a percent sign marker just changes a double asterisk marker from the previous example to show that both of them have the same use.

Another commenting method is the C style. A C style comment starts with the start comment mark /* and terminates with the end comment mark */. The C style enables closing a text in the middle of an expression, or closing several text lines.

Example:

/*

This is a multiple line comment.

All this text is ignored.

*/

if ( 1 /* x == 1 */ ) y = 1;

end

The expression y = 1 will be always executed. The x==1 condition enclosed by the comment markers is ignored.

34

5.5Program Flow Commands

The Amplifier has a set of commands that manage the flow of the user program.

With the aid of these commands, the user program can make decisions iterate, or respond automatically to some events.

The program flow commands enable user programs to do much more complicated things then just running a set of commands sequentially.

The program flow commands are:

while end : Iterate as long as a condition is satisfied.

until : Iterate (suspend the execution of the program) until a condition is satisfied.

Page 36
Image 36
Elmo HARmonica, HARSFEN0602 software manual Program Flow Commands, Example