Comparison Operations

In this section, we will discuss how to perform comparisons between variables/values.

- Table of Contents -

Comparison Operators

In programming, it's often necessary to compare values to determine conditions for branching or other logic. This is where comparison operators come into play. VCSSL provides the following comparison operators:

Symbol Meaning Supported Types Details
 < Is left less than right? int,
float,
varint,
varfloat
Compares the two values and checks if the left value is smaller than the right value (*).
 > Is left greater than right? int,
float,
varint,
varfloat
Compares the two values and checks if the left value is greater than the right value.
 <= Is left less than or equal to right? int,
float,
varint,
varfloat
Compares the two values and checks if the left value is smaller than or equal to the right value.
 >= Is left greater than or equal to right? int,
float,
varint,
varfloat
Compares the two values and checks if the left value is greater than or equal to the right value.
 == Are left and right equal? int,
float,
varint,
varfloat,
string,
struct
Compares the two values and checks if they are equal.
 != Are left and right different? int,
float,
varint,
varfloat,
string,
struct
Compares the two values and checks if they are different.

*: All results are of bool type.

About "bool" Type

As mentioned above, the result of comparison operations is of the "bool" type. This is a data type that can take two values: "true" or "false." The type name "bool" is an abbreviation of "boolean", so, sometimes, it is referred to as a "boolean" type in some other languages.

While terms like "true" and "false" may not immediately resonate, in most cases, you can consider that "true" means "YES" and "false" means "NO."

Performing Comparisons

Now, let's actually perform some comparison operations. Here, we'll use the symbol "<" to check if the left side is smaller than the right side:

Comp1LT2.vcssl

- Execution Result -

true

When you execute this, it will display "true." Here, "true" ("YES") indicates that the left side is smaller than the right side.

On the other hand, what do you think will happen with the following example:

Comp2LT1.vcssl

- Execution Result -

false

When you execute this, it will display "false" ("NO"). This indicates that the left side is not smaller than the right side.

Checking for Equality

Next, let's examine equality of two values. Here, we'll use the "==" symbol to check if the left and right sides are equal:

Comp1EQ1.vcssl

- Execution Request -

true

When you execute this, it will display "true."

What will happen in the following example:

Comp1EQ2.vcssl

- Execution Request -

false

In this case, it will display "false."

Additionally, you can check for inequality as follows:

Comp1NEQ2.vcssl

- Execution Request -

true

In this case, it will display "true." This indicates that the left and right sides are different.

Furthermore, such conditional checks can also be expressed using the negation operator "!." The negation operator returns "false" if its operand is true and "true" if its operand is false.

For example, "!(A==B)," the negation of "A==B," checks if the left and right sides are different:

CompNOT1EQ2.vcssl

- Execution Result -

true

In this case, it also returns "true" since it represents the same condition.

Acknowledgement: We greatly appreciate the cooperation of two ChatGPT AIs in translating this page.
» How we translated this page