ProtoLang.net

Reference: Is Greater Than

☰ Hide Sidebar
TOKEN IS GREATER THAN
ALIAS >

The Is Greater Than Comparison Operator checks whether the left value is larger than the right value. This operator evaluates to True if the left value is greater 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 GREATER THAN:

VALUE IS GREATER THAN VALUE

Basic Comparisons

Example: Comparing Integer Literals

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

Example: Comparing Float Literals

PRINTLN 5.7 > 2.5 // Displays "TRUE"
PRINTLN 2.0 > 5.0 // Displays "FALSE"
PRINTLN 3.14 > 3.14 // Displays "FALSE"

Example: Comparing Negative Numbers

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

Comparing Variables

Example: Integer Variable Comparison

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

Example: Float Variable Comparison

NEW FLOAT temp1 = 100.0
NEW FLOAT temp2 = 98.6
NEW BOOL isHotter = temp1 > temp2
PRINTLN isHotter // Displays "TRUE"

Example: Comparing Variable to Literal

NEW INT age = 25
NEW BOOL isAdult = age > 18
PRINTLN isAdult // Displays "TRUE"

Using Is Greater Than in Conditionals

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

Example: Age Validation

NEW INT age = 21
IF age > 18
    PRINTLN "Access granted"
ELSE
    PRINTLN "Access denied: Must be over 18"
END IF
// Displays "Access granted"

Example: Temperature Check

NEW FLOAT temperature = 85.0
IF temperature > 90.0
    PRINTLN "Very hot"
ELIF temperature > 70.0
    PRINTLN "Warm"
ELSE
    PRINTLN "Cool or cold"
END IF
// Displays "Warm"

Example: Score Grading

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

Using Is Greater Than in Loops

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

Example: Countdown Loop

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

Example: Processing Above Threshold

NEW INT value = 20
WHILE value > 10
    PRINTLN "Value: " .. value
    SET value = value - 2
END WHILE
// Displays: Value: 20, Value: 18, Value: 16, Value: 14, Value: 12

Example: Depleting Resources

NEW INT fuel = 100
WHILE fuel > 0
    PRINTLN "Fuel remaining: " .. fuel
    SET fuel = fuel - 25
END WHILE
PRINTLN "Out of fuel"

Comparing Expression Results

Example: Checking Arithmetic Results

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

Example: Checking Multiplication Results

NEW INT width = 5
NEW INT height = 6
NEW BOOL isLarge = ( width * height ) > 25
PRINTLN isLarge // Displays "TRUE" ( 30 > 25 )

Example: Comparing Multiple Expressions

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

Combining with Logical Operators

Example: Range Checking

NEW INT value = 15
NEW BOOL outOfRange = ( value > 20 ) || ( value > 50 )
PRINTLN outOfRange // Displays "FALSE"

Example: Multiple Threshold Checks

NEW INT score = 85
NEW BOOL isPassing = ( score > 60 ) && ( score > 50 )
PRINTLN isPassing // Displays "TRUE"

Example: Complex Conditions

NEW INT age = 25
NEW BOOL hasExperience = TRUE
NEW BOOL isQualified = ( age > 21 ) && hasExperience
PRINTLN isQualified // Displays "TRUE"

Practical Applications

Example: Overtime Hours Check

NEW INT hoursWorked = 45
NEW INT regularHours = 40
IF hoursWorked > regularHours
    PRINTLN "Overtime pay applies"
ELSE
    PRINTLN "Regular pay only"
END IF
// Displays "Overtime pay applies"

Example: High Score Detection

NEW INT currentScore = 1500
NEW INT highScore = 1000
IF currentScore > highScore
    PRINTLN "New high score!"
ELSE
    PRINTLN "Keep trying"
END IF
// Displays "New high score!"

Example: Finding Maximum Value

NEW INT a = 25
NEW INT b = 18
NEW INT maximum = 0
IF a > b
    SET maximum = a
ELSE
    SET maximum = b
END IF
PRINTLN "Maximum value: " .. maximum
// Displays "Maximum value: 25"

Example: Alert System

NEW FLOAT temperature = 105.0
NEW FLOAT dangerThreshold = 100.0
IF temperature > dangerThreshold
    PRINTLN "WARNING: Temperature exceeds safe limit!"
ELSE
    PRINTLN "Temperature within normal range"
END IF
// Displays "WARNING: Temperature exceeds safe limit!"

Boundary Behavior

Example: Equal Values Return False

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

Example: Use Greater Than Or Equal To for Inclusive Checks

NEW INT score = 90
// Wrong for inclusive threshold
IF score > 90
    PRINTLN "Above threshold"
END IF
// Correct for inclusive threshold
IF score >= 90
    PRINTLN "At or above threshold"
END IF
// Displays "At or above threshold"

Is Greater Than vs Is Less Than

Is Greater Than checks if the left value is larger, while Is Less Than checks if the left value is smaller.

Example: Opposite Comparisons

NEW INT x = 15
NEW INT y = 10
PRINTLN x > y // Displays "TRUE"
PRINTLN x < y // Displays "FALSE"
PRINTLN y > x // Displays "FALSE"
PRINTLN y < x // Displays "TRUE"

Common Use Cases

Example: Eligibility Check

NEW INT credits = 125
NEW INT requiredCredits = 120
IF credits > requiredCredits
    PRINTLN "Eligible for graduation"
ELSE
    PRINTLN "Need more credits"
END IF
// Displays "Eligible for graduation"

Example: Speed Violation

NEW INT speed = 75
NEW INT speedLimit = 65
IF speed > speedLimit
    PRINTLN "Speeding! Slow down."
ELSE
    PRINTLN "Speed is acceptable"
END IF
// Displays "Speeding! Slow down."

Example: Priority Queue

NEW INT taskPriority = 8
NEW INT highPriorityThreshold = 7
IF taskPriority > highPriorityThreshold
    PRINTLN "High priority task - process immediately"
ELSE
    PRINTLN "Normal priority task"
END IF
// Displays "High priority task - process immediately"

Example: Sensor Reading

NEW FLOAT pressure = 45.5
NEW FLOAT maxPressure = 40.0
IF pressure > maxPressure
    PRINTLN "Pressure relief valve activated"
ELSE
    PRINTLN "Pressure normal"
END IF
// Displays "Pressure relief valve activated"

Filtering and Searching

Example: Filter Values Above Threshold

NEW INT i = 1
WHILE i <= 10
    IF i > 5
        PRINTLN "Value above threshold: " .. i
    END IF
    SET i = i + 1
END WHILE
// Displays values 6 through 10

Example: Finding First Value Above Target

NEW INT value = 1
NEW INT target = 50
WHILE value <= 100
    IF value > target
        PRINTLN "First value above target: " .. value
        BREAK
    END IF
    SET value = value + 10
END WHILE

Important Notes

  • Is Greater Than ( > ) returns True only if the left value is strictly larger than the right value.
  • Equal values return False; use Is Greater 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 Greater Than.

Common Errors

Error: Mixing Integer and Float

NEW INT x = 10
NEW FLOAT y = 5.0
PRINTLN x > y // Type error! Cannot mix Integer and Float

Error: Using with Strings

NEW STR name1 = "Bob"
NEW STR name2 = "Alice"
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 points = 100
IF points > 100 // FALSE when points is exactly 100
    PRINTLN "Over 100 points"
END IF
// Use >= for inclusive check
IF points >= 100
    PRINTLN "100 points or more"
END IF
// Displays "100 points or more"