ProtoLang.net

Reference: Is Less Than Or Equal To

☰ Hide Sidebar
TOKEN IS LESS THAN OR EQUAL TO
ALIAS <=

The Is Less Than Or Equal To Comparison Operator checks whether the left value is smaller than or equal to the right value. This operator evaluates to True if the left value is less than or equal to 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 OR EQUAL TO:

VALUE IS LESS THAN OR EQUAL TO VALUE

Basic Comparisons

Example: Comparing Integer Literals

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

Example: Comparing Float Literals

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

Example: Comparing Negative Numbers

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

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 "TRUE"

Example: Float Variable Comparison

NEW FLOAT temp1 = 98.6
NEW FLOAT temp2 = 100.0
NEW FLOAT temp3 = 98.6
NEW BOOL isNotHotter = temp1 <= temp2
NEW BOOL isSame = temp1 <= temp3
PRINTLN isNotHotter // Displays "TRUE"
PRINTLN isSame // Displays "TRUE"

Example: Comparing Variable to Literal

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

Using Is Less Than Or Equal To in Conditionals

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

Example: Age Validation with Boundary

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

Example: Temperature Check

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

Example: Score Grading with Inclusive Boundaries

NEW INT score = 80
IF score <= 59
    PRINTLN "Grade: F"
ELIF score <= 69
    PRINTLN "Grade: D"
ELIF score <= 79
    PRINTLN "Grade: C"
ELIF score <= 89
    PRINTLN "Grade: B"
ELSE
    PRINTLN "Grade: A"
END IF
// Displays "Grade: B"

Using Is Less Than Or Equal To in Loops

The Is Less Than Or Equal To operator is frequently used to control loop iterations with inclusive boundaries.

Example: Inclusive 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, Count: 5

Example: Processing Until Threshold Reached

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

Example: Countdown to Zero

NEW INT timer = 5
WHILE timer <= 5
    PRINTLN "Timer: " .. timer
    SET timer = timer - 1
    IF timer <= 0
        PRINTLN "Time's up!"
        BREAK
    END IF
END WHILE

Comparing Expression Results

Example: Checking Arithmetic Results

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

Example: Checking Division Results

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

Example: Comparing Multiple Expressions

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

Combining with Logical Operators

Example: Range Checking

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

Example: Multiple Threshold Checks

NEW INT score = 100
NEW BOOL isPerfect = ( score <= 100 ) && ( score <= 100 )
PRINTLN isPerfect // Displays "TRUE"

Example: Complex Conditions

NEW INT age = 18
NEW BOOL hasID = TRUE
NEW BOOL canEnter = ( age <= 21 ) || hasID
PRINTLN canEnter // Displays "TRUE"

Practical Applications

Example: Capacity Check

NEW INT attendees = 100
NEW INT capacity = 100
IF attendees <= capacity
    PRINTLN "Venue can accommodate all attendees"
ELSE
    PRINTLN "Venue overcapacity"
END IF
// Displays "Venue can accommodate all attendees"

Example: Budget Validation

NEW FLOAT spent = 250.50
NEW FLOAT budget = 300.00
IF spent <= budget
    PRINTLN "Within budget"
ELSE
    PRINTLN "Over budget!"
END IF
// Displays "Within budget"

Example: Finding Maximum Allowed Value

NEW INT input = 50
NEW INT maxAllowed = 50
IF input <= maxAllowed
    PRINTLN "Valid input: " .. input
ELSE
    PRINTLN "Input exceeds maximum allowed value"
END IF
// Displays "Valid input: 50"

Example: Countdown Timer

NEW INT seconds = 10
WHILE seconds <= 10
    IF seconds <= 0
        PRINTLN "Launch!"
        BREAK
    END IF
    PRINTLN "T-minus " .. seconds .. " seconds"
    SET seconds = seconds - 1
END WHILE

Is Less Than Or Equal To vs Is Less Than

The key difference is that Is Less Than Or Equal To ( <= ) includes equal values, while Is Less Than ( < ) does not.

Example: Boundary Comparison

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

Example: Inclusive vs Exclusive Range

NEW INT score = 100
NEW INT maxScore = 100
// Exclusive check ( wrong for this case )
IF score < maxScore
    PRINTLN "Below maximum"
END IF
// Inclusive check ( correct )
IF score <= maxScore
    PRINTLN "At or below maximum"
END IF
// Displays "At or below maximum"

Boundary Behavior

Example: Equal Values Return True

NEW INT x = 25
NEW INT y = 25
PRINTLN x <= y // Displays "TRUE" ( 25 is equal to 25 )

Example: Loop with Inclusive Upper Bound

NEW INT i = 1
NEW INT target = 3
WHILE i <= target
    PRINTLN "Iteration " .. i
    SET i = i + 1
END WHILE
// Displays: Iteration 1, Iteration 2, Iteration 3

Common Use Cases

Example: Validating User Input Range

NEW INT userInput = 5
NEW INT minValue = 1
NEW INT maxValue = 10
IF ( minValue <= userInput ) && ( userInput <= maxValue )
    PRINTLN "Valid input"
ELSE
    PRINTLN "Input out of range"
END IF
// Displays "Valid input"

Example: Grading with Boundaries

NEW INT points = 90
IF points <= 100
    IF points <= 89
        PRINTLN "Not quite an A"
    ELSE
        PRINTLN "Grade A!"
    END IF
END IF
// Displays "Grade A!"

Example: Inventory Management

NEW INT stock = 10
NEW INT reorderPoint = 10
IF stock <= reorderPoint
    PRINTLN "Time to reorder!"
ELSE
    PRINTLN "Stock level adequate"
END IF
// Displays "Time to reorder!"

Example: Processing Fixed Number of Items

NEW INT processed = 0
NEW INT total = 5
WHILE processed <= total
    SET processed = processed + 1
    PRINTLN "Processing item " .. processed
    IF processed <= total
        PRINTLN "More items to process"
    ELSE
        PRINTLN "All items processed"
    END IF
    IF processed <= total
        // Continue
    ELSE
        BREAK
    END IF
END WHILE

Important Notes

  • Is Less Than Or Equal To ( <= ) returns True if the left value is smaller than or equal to the right value.
  • Equal values return True; use Is Less Than ( < ) for strictly smaller 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 Or Equal To.
  • Use <= for inclusive upper bounds in loops and range checks.

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: Using Wrong Operator for Exclusive Comparison

NEW INT age = 18
// Wrong if you want to exclude 18
IF age <= 18
    PRINTLN "18 or younger" // This includes 18
END IF
// Correct for exclusive check
IF age < 18
    PRINTLN "Under 18" // This excludes 18
END IF
// Displays "18 or younger"