ProtoLang.net

Reference: Is Less Than

☰ Hide Sidebar
TOKEN IS LESS THAN
ALIAS <

The Is Less Than Comparison Operator checks whether the left value is smaller than the right value. This operator evaluates to True if the left value is less than the right value, and False otherwise. It works with Integer and Float types, but cannot mix different numeric types.

Syntax

The short syntax structure uses the < symbol:

VALUE < VALUE

The long syntax structure uses the words IS LESS THAN:

VALUE IS LESS THAN VALUE

Basic Comparisons

Example: Comparing Integer Literals

PRINTLN 5 < 10 // Displays "TRUE"
PRINTLN 10 < 5 // Displays "FALSE"
PRINTLN 5 < 5 // Displays "FALSE"

Example: Comparing Float Literals

PRINTLN 2.5 < 3.7 // Displays "TRUE"
PRINTLN 5.0 < 2.0 // Displays "FALSE"
PRINTLN 3.14 < 3.14 // Displays "FALSE"

Example: Comparing Negative Numbers

PRINTLN -5 < 0 // Displays "TRUE"
PRINTLN -10 < -5 // Displays "TRUE"
PRINTLN 0 < -5 // Displays "FALSE"

Comparing Variables

Example: Integer Variable Comparison

NEW INT x = 10
NEW INT y = 20
NEW INT z = 10
PRINTLN x < y // Displays "TRUE"
PRINTLN y < x // Displays "FALSE"
PRINTLN x < z // Displays "FALSE"

Example: Float Variable Comparison

NEW FLOAT temp1 = 98.6
NEW FLOAT temp2 = 100.0
NEW BOOL isCooler = temp1 < temp2
PRINTLN isCooler // Displays "TRUE"

Example: Comparing Variable to Literal

NEW INT age = 17
NEW BOOL isMinor = age < 18
PRINTLN isMinor // Displays "TRUE"

Using Is Less Than in Conditionals

The Is Less Than operator is commonly used in If statements to check numeric thresholds.

Example: Age Validation

NEW INT age = 16
IF age < 18
    PRINTLN "Access denied: Must be 18 or older"
ELSE
    PRINTLN "Access granted"
END IF
// Displays "Access denied: Must be 18 or older"

Example: Temperature Check

NEW FLOAT temperature = 32.0
IF temperature < 32.0
    PRINTLN "Below freezing"
ELIF temperature < 50.0
    PRINTLN "Cold"
ELSE
    PRINTLN "Moderate or warm"
END IF
// Displays "Cold"

Example: Score Grading

NEW INT score = 75
IF score < 60
    PRINTLN "Grade: F"
ELIF score < 70
    PRINTLN "Grade: D"
ELIF score < 80
    PRINTLN "Grade: C"
ELIF score < 90
    PRINTLN "Grade: B"
ELSE
    PRINTLN "Grade: A"
END IF
// Displays "Grade: C"

Using Is Less Than in Loops

The Is Less Than operator is frequently used to control loop iterations.

Example: Basic Counting Loop

NEW INT i = 1
WHILE i < 5
    PRINTLN "Count: " .. i
    SET i = i + 1
END WHILE
// Displays: Count: 1, Count: 2, Count: 3, Count: 4

Example: Processing Until Threshold

NEW INT value = 0
WHILE value < 10
    SET value = value + 2
    PRINTLN "Value: " .. value
END WHILE
// Displays: Value: 2, Value: 4, Value: 6, Value: 8, Value: 10

Example: Countdown

NEW INT fuel = 100
WHILE fuel < 100
    PRINTLN "Fuel level: " .. fuel
    SET fuel = fuel + 10
END WHILE
PRINTLN "Tank full"

Comparing Expression Results

Example: Checking Arithmetic Results

NEW INT x = 10
NEW INT y = 5
NEW BOOL result = ( x + y ) < 20
PRINTLN result // Displays "TRUE" ( 15 < 20 )

Example: Checking Division Results

NEW INT total = 100
NEW INT parts = 3
NEW BOOL isSmall = ( total / parts ) < 40
PRINTLN isSmall // Displays "TRUE" ( 33 < 40 )

Example: Comparing Multiple Expressions

NEW INT a = 5
NEW INT b = 3
NEW INT c = 10
NEW BOOL comparison = ( a + b ) < ( c * 2 )
PRINTLN comparison // Displays "TRUE" ( 8 < 20 )

Combining with Logical Operators

Example: Range Checking

NEW INT value = 15
NEW BOOL inRange = ( value < 20 ) && ( value < 50 )
PRINTLN inRange // Displays "TRUE"

Example: Multiple Threshold Checks

NEW FLOAT temperature = 25.0
NEW BOOL isCold = ( temperature < 10.0 ) || ( temperature < 15.0 )
PRINTLN isCold // Displays "FALSE"

Example: Complex Conditions

NEW INT age = 16
NEW BOOL hasPermission = FALSE
NEW BOOL canEnter = ( age < 18 ) && hasPermission
PRINTLN canEnter // Displays "FALSE"

Practical Applications

Example: Stock Level Alert

NEW INT stock = 5
NEW INT minStock = 10
IF stock < minStock
    PRINTLN "Warning: Low stock level"
ELSE
    PRINTLN "Stock level adequate"
END IF
// Displays "Warning: Low stock level"

Example: Speed Limit Check

NEW INT speed = 45
NEW INT speedLimit = 50
IF speed < speedLimit
    PRINTLN "Within speed limit"
ELSE
    PRINTLN "Speeding!"
END IF
// Displays "Within speed limit"

Example: Finding Minimum Value

NEW INT a = 25
NEW INT b = 18
NEW INT minimum = 0
IF a < b
    SET minimum = a
ELSE
    SET minimum = b
END IF
PRINTLN "Minimum value: " .. minimum
// Displays "Minimum value: 18"

Example: Progress Tracking

NEW INT completed = 7
NEW INT total = 10
IF completed < total
    PRINTLN "Progress: " .. completed .. "/" .. total .. " - Not complete"
ELSE
    PRINTLN "All tasks completed!"
END IF
// Displays "Progress: 7/10 - Not complete"

Boundary Behavior

Example: Equal Values Return False

NEW INT x = 10
NEW INT y = 10
PRINTLN x < y // Displays "FALSE" ( 10 is not less than 10 )

Example: Use Less Than Or Equal To for Inclusive Checks

NEW INT score = 80
// Wrong for inclusive threshold
IF score < 80
    PRINTLN "Below threshold"
END IF
// Correct for inclusive threshold
IF score <= 80
    PRINTLN "At or below threshold"
END IF
// Displays "At or below threshold"

Important Notes

  • Is Less Than ( < ) returns True only if the left value is strictly smaller than the right value.
  • Equal values return False; use Is Less Than Or Equal To ( <= ) for inclusive comparisons.
  • Both values must be the same numeric Data Type ( both Integer or both Float ).
  • The result is always a Boolean ( True or False ).
  • Cannot compare Strings or Booleans with Is Less Than.

Common Errors

Error: Mixing Integer and Float

NEW INT x = 5
NEW FLOAT y = 10.0
PRINTLN x < y // Type error! Cannot mix Integer and Float

Error: Using with Strings

NEW STR name1 = "Alice"
NEW STR name2 = "Bob"
PRINTLN name1 < name2 // Type error! Cannot compare Strings with <

Error: Using with Booleans

NEW BOOL a = TRUE
NEW BOOL b = FALSE
PRINTLN a < b // Type error! Cannot compare Booleans with <

Error: Expecting Inclusive Comparison

NEW INT age = 18
IF age < 18 // FALSE when age is exactly 18
    PRINTLN "Under 18"
END IF
// Use <= for inclusive check
IF age <= 18
    PRINTLN "18 or under"
END IF
// Displays "18 or under"