The Operations Symbols; Conditional Execution - HP E1419A User Manual

Measurement and control module
Table of Contents

Advertisement

NOTE
The Operations
Symbols
The Arithmetic
Operators
Unary Arithmetic
Operator
The Comparison
Operators
The Logical Operators
Conditional
Execution
Chapter 4
In BASIC the assignment symbol "=" is also used as the comparison
operator "is equal to". For example; IF a=b THEN ... . As you will read a
little further on, 'C' uses a different symbol for this comparison.
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 you get used to them.
The arithmetic operators available to the HP E1419A are the same as those
equivalents in BASIC:
(addition)
+
(multiplication)
*
Again same as BASIC:
(unary minus)
-
(unary plus)
+
Here there are some differences.
BASIC
(is equal to)
=
<> or #
(is not equal to)
(is greater than)
>
(is less than)
<
(is greater than or equal to) >=
>=
(is less than or equal to)
<=
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 HP E1419A will flag this
as a Syntax Error when the algorithm is loaded.
There are three operators. They are very different from those in BASIC.
BASIC
Examples
AND
IF A=B AND B=C
OR
IF A=B OR A=C
NOT
IF NOT B
The HP E1419A 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
The Algorithm Language and Environment 139
(subtraction)
-
(division)
/
Examples:
a = b + (-c)
a = c + (+b)
'C'
Different (hard to remember)
==
Different but obvious
!=
Same
>
Same
>
Same
Same
<=
'C'
Examples
&&
if( ( a == b )&&( b == c ) )
||
if( ( a == b ) || ( a == c ) )
!
if ( ! b )
Notes

Advertisement

Table of Contents
loading

Table of Contents