Back | Next Lesson

Evaluating Data

It is now time to compare values against one another.  Values can come in the form of variables or constants (Lesson #004), numerals or character strings.

The following operators are used in conjunction with conditional statements (
if/endif, etc.) to control the flow or logic of your program.  Bare with me, it tough to talk about evaluating data without getting wrapped up in conditional statements.  To put both in this weekly lesson would violate the main principle of keeping the lessons as simple as possible.  Next week we'll jump into Conditional Statements.

Expressions

Expressions can be either be a single value, an equation that equates to a single value, or a $utility that returns a single value.  Again, the value can be either a number or string.

Relative Comparisons

Relational operators require 2 values, making them binary operators. Relational operators numerically (which includes ASCII values) compares one expression relative to another expression for trueness. 

Relational operators test for:
                                2 Syntax Options
You can use either syntax options mentioned above, Sigmac recognizes both.
Note: The equal (=) character is used in both testing for equality and assigning a value to a variable.  The former uses a double (==) equal characters and the latter uses a single (=) equal character.

Relational Operator Examples:

006     i1 = 100
007     i2 = 100
008     i3 = 200
009
010
     if i1 == i2             /* Test for Equality
011             . . . . .
012     endif
013     if i1 <> i3             /* Test for Non-Equality
014             . . . . .
015     endif
016     if i1 <= i2             /* Test for Less-Than or Equal
017             . . . . .
018     endif
019     if i3 >= i2             /* Test for Greater Than or Equal
020             . . . . .
021     endif
022     if i1 < i3              /* Test for Less Than
023             . . . . .
024     endif
025     if i3 > i1              /* Test for Greater-Than
026             . . . . .
027     endif

All relational comparisons in the above examples evaluate to #true, therefore the subcode within the if/endif statements will execute.  Get the idea.  Evaluating data in combination with conditional statements will control the flow of your program.  In other words, which part of your program will execute under which conditions.

Logical Comparisons

Logical operators compare (not numerically, but logically) one expression's trueness relative to another expression's trueness, returning either #true (1) or #false (0).
Logical operators test for:
                                                Syntax
Most logical operators require 2 expressions, making them binary operators.  Only the 'negation' (.not.) operator requires a single expression, making it a unary operator.

Logical Operator Examples:

006     i1 = 100
007     i2 = 100
008     i3 = 200
009
010
     if i1 == i2 .and. i1 < i3       /* Both Expressions Must Be True
011             . . . . .
012     endif
013     if i1 <> i3 .or.  i1 == i2      /* Either or Both May Be True
014             . . . . .
015     endif
016     if i1 <= i2 .xor. i1 == i3      /* Either, But Not Both May Be True
017             . . . . .
018     endif
019     if .not.(i3 == i2)                      /* Test for Non-Equality
020             . . . . .
021     endif

All logical comparisons in the above example evaluate to #true, therefore the subcode within the if/endif statements will execute.  Line #019 returns #false within the parenthesis and the negation (.not.) of #false is #true.  Lines #010, 013, and 016 are also known as compounded statements, evaluating multiple expressions.

We could have written line #010 as: 
010     if i1 == i2
011             if i1 < i3
012                     . . . . .
013             endif
014     endif

We could have written line #013 as: 
013     if i1 <> i3
014             . . . . .
015     endif
016     if i1 == i2
017             . . . . .
018     endif

Line #016 would be more difficult to write without logical operator,  .xor. .

We could have written line #019 as:
019     if i3 <> i2
020             . . . . .
021     endif


That's all for now,
Steve


This lesson was brought to you by SCG consulting. All written materials related to these Sigmac lessons are copyrighted by SCG and intended for personal use only. Any commercial or non-commercial reproduction for public use is prohibited without written consent from SCG.

Back | Next Lesson