The operations symbols, The arithmetic operators, Unary arithmetic operator – VXI VT1422A User Manual

Page 220: The comparison operators, The logical operators, Conditional execution, The operations symbols conditional execution

Advertising
background image

218 Creating and Running Algorithms

Chapter 6

The Operations

Symbols

Many of the operation symbols are the same and are used the same way as
those in BASIC. However, there are differences and they can cause
programming errors until the differences become familiar.

The Arithmetic Operators

The arithmetic operators available to the VT1422A are the same as those
equivalents in BASIC:
+

(addition)

-

(subtraction)

*

(multiplication)

/

(division)

Unary Arithmetic

Operator

Again same as BASIC:
-

(unary minus)

Examples:

a = b + (-c)

+

(unary plus)

a = c + (+b)

The Comparison

Operators

Here there are some differences.

BASIC

'C'

Notes

=

(is equal to)

==

Different (hard to remember)

<> or #

(is not equal to)

!=

Different but obvious

>

(is greater than)

>

Same

<

(is less than)

>

Same

>=

(is greater than or equal to)

>=

Same

<=

(is less than or equal to)

<=

Same

A common 'C' programming error for BASIC programmers is to
inadvertently use the assignment operator "=" instead of the comparison
operator "==" in an if statement. Fortunately, the VT1422A will flag this as
a Syntax Error when the algorithm is loaded.

The Logical Operators

There are three operators. They are very different from those in BASIC.

BASIC

Examples

'C'

Examples

AND

IF A=B AND B=C

&&

if( ( a == b )&&( b == c ) )

OR

IF A=B OR A=C

| |

if( ( a == b ) | | ( a == c ) )

NOT

IF NOT B

!

if ( ! b )

Conditional

Execution

The VT1422A Algorithm Language provides the if - else construct for
conditional execution. The following figure compares the elements of the 'C'
if - else construct with the BASIC if - then - else - end if construct.
The general form of the if - else construct is:

if(expression) statement1 else statement2

where statement1 is executed if expression evaluates to non-zero (true),
and statement2 is executed if expression evaluates to zero (false).
Statement1 and/or statement2 can be compound statements. That is,
multiple simple statements within curly braces (see Figure 6-5).

Advertising
This manual is related to the following products: