Previous page Next page Navigation bar

Calculator Programming Tutorial

Programming Building Blocks I

Expressions

Relational Operators

Mathematics has a rich set of relational operators. These operators include equality and inequality tests (a = b, ab), strict ordering tests (a < b, a > b), and ordering or equality tests (a Less than or equal to b, a Greater than or equal to b). All of the languages also define all these operators. However, JavaScript and Visual Basic for Applications are written using ASCII characters, and the ASCII character set does not include the symbols ≠, Less than or equal to, or Greater than or equal to. Further, JavaScript actually defines assignment as an operator, rather than a statement: so JavaScript already has an operator =, so it must use something else in order to test for equality.

The character sequences used in each of the calculator, JavaScript, and Visual Basic for Applications for these relational operators are as follows:

Test

Mathematics

Calculator

JavaScript

VBA

Equality

=

=

==

=

Inequality

!=

<>

Less than

<

<

<

<

Less than or equal to

Less than or equal to

Less than or equal to

<=

<= or =<

Greater than

>

>

>

>

Greater than or equal to

Greater than or equal to

Greater than or equal to

>=

>= or =>

There are several items to note in this table. These are discussed in the sections that follow.

Calculator Symbols

Unsurprisingly, the calculator has distinct symbols for ≠, Less than or equal to, and Greater than or equal to. These are obtained by choosing the appropriate operation from the relational operation menu. This is not surprising as the calculator uses its own character set, one optimized for the calculator’s functions.

JavaScript Symbols

JavaScript uses two equal signs, ==, as its equality operator, rather than one equal sign. As noted before, this is because JavaScript’s assignment is actually an operator, rather than a statement. This can cause some confusion, as the construct:

if (a = b)
{
    statements;
}

is perfectly legal, although frequently not what is desired. Its effect is to assign b to a, then to test the value for equality with zero. If b (and now a) is non-zero, the statement sequence statements is executed. This can frequently be guarded against by forming the habit of putting all constants in an equality relational on the left side.

JavaScript also uses != as its inequality operator. This combines the unary logical negation operator, !, with the = assignment operator. This can be confusing, as JavaScript has a rich set of assignment operators, including +=, -=, *=, /=, <<=, >>=, >>>=, %=, &=, |=, and ^=. These assignment operators combine the operation (+, -, etc.) on the two operands with assignment to the left operand. !=, however, is unique among these operators formed by combining an operator with the assignment operator, in that it does not also produce an assignment.

JavaScript also has another equality-like comparison operator, ===, the identity operator. Given the pattern above, one would expect this operator to perform an equality test and to assign the results to the left operand, but it does not do that.

In JavaScript’s <= and >= operators, the order of the characters in the relational operator is important. The angle bracket must come before the equal sign. The constructs =< and => are syntax errors.

Visual Basic for Applications Symbols

VBA uses a single equal sign, =, for its equality relational operator. It can do this because it can always tell the difference between an assignment and a relational operator. For example, the statement:

a = b = c

Compares the two quantities b and a, and assigns the result of that comparison to a.

VBA combines the less than sign, <, and the greater than sign, >, to form its inequality operator, <>.

Finally, VBA allows both of <= and =< for less than or equal to, and both of >= and => for greater than or equal to. The VBA programming environment, however, will automatically change the forms with the leading equal sign (=< and =>) to the forms with the trailing equal sign (<= and >=).

[ Previous page | Top of page | Next page ]

Previous page Top of page Next page Navigation bar

Copyright © 2002 Brian Hetrick
Page last updated 13 January 2002.

Brian’s Casio Calculator Corner

Home

Programs

Tutorial

Preface

Introduction

Fundamentals

Building Blocks I

Introduction

Comments

Data Types

Numbers

Variables

Expressions

Introduction

Arithmetic

Grouping

Relational

Logical

Bitwise

String

Side Effect

Functions

Control Flow I

Control Flow II

Subprograms

Basic I/O

Algorithms

A First Program

Examples

Exercises

Answers

Modularization

Data Structures I

Recursion

Program Attributes

Building Blocks II

Algorithm Analysis

Structuring

Data Structures II

Abstract Types

Objects

Problem Analysis

Reference Card

References

Puzzles

Site Information

Your Privacy

Site Map

E-mail

Site Technical Data