The Is Not Equal To Comparison Operator checks whether two values are different. This operator evaluates to True if the values are not the same, and False if they are identical. It is the logical opposite of the Is Equal To operator.
The short syntax structure uses the != symbol:
VALUE != VALUEThe long syntax structure uses the words IS NOT EQUAL TO:
VALUE IS NOT EQUAL TO VALUEPRINTLN 5 != 10 // Displays "TRUE"
PRINTLN 5 != 5 // Displays "FALSE"
PRINTLN 0 != 1 // Displays "TRUE"PRINTLN 3.14 != 2.71 // Displays "TRUE"
PRINTLN 2.5 != 2.5 // Displays "FALSE"
PRINTLN 1.0 != 1.5 // Displays "TRUE"PRINTLN "Hello" != "World" // Displays "TRUE"
PRINTLN "Hello" != "Hello" // Displays "FALSE"
PRINTLN "abc" != "xyz" // Displays "TRUE"PRINTLN TRUE != FALSE // Displays "TRUE"
PRINTLN TRUE != TRUE // Displays "FALSE"
PRINTLN FALSE != TRUE // Displays "TRUE"NEW INT x = 10
NEW INT y = 20
NEW INT z = 10
PRINTLN x != y // Displays "TRUE"
PRINTLN x != z // Displays "FALSE"NEW STR name1 = "Alice"
NEW STR name2 = "Bob"
NEW STR name3 = "Alice"
NEW BOOL areDifferent = name1 != name2
NEW BOOL areSame = name1 != name3
PRINTLN areDifferent // Displays "TRUE"
PRINTLN areSame // Displays "FALSE"NEW STR password = "secret123"
NEW BOOL isWrong = password != "wrong_password"
PRINTLN isWrong // Displays "TRUE"The Is Not Equal To operator is commonly used in If statements to check when values differ.
NEW STR username = "admin"
IF username != ""
PRINTLN "Username provided"
ELSE
PRINTLN "Username required"
END IF
// Displays "Username provided"NEW STR status = "pending"
IF status != "complete"
PRINTLN "Task is not finished"
ELSE
PRINTLN "Task is complete"
END IF
// Displays "Task is not finished"NEW INT errorCode = 404
IF errorCode != 0
PRINTLN "An error occurred: " .. errorCode
ELSE
PRINTLN "Operation successful"
END IF
// Displays "An error occurred: 404"The Is Not Equal To operator can control loop continuation by checking when values remain different.
NEW INT guess = 1
NEW INT target = 5
WHILE guess != target
PRINTLN "Guess: " .. guess
SET guess = guess + 1
END WHILE
PRINTLN "Found target: " .. target
// Displays: Guess: 1, Guess: 2, Guess: 3, Guess: 4, Found target: 5NEW INT i = 1
NEW INT sentinel = 0
WHILE i != sentinel
PRINTLN "Processing item " .. i
SET i = i - 1
IF i < -2
SET i = sentinel // Stop condition
END IF
END WHILE
PRINTLN "Done processing"NEW INT x = 10
NEW INT y = 5
NEW BOOL result = ( x + y ) != 20
PRINTLN result // Displays "TRUE" ( 15 != 20 )NEW INT number = 7
NEW BOOL isOdd = ( number % 2 ) != 0
PRINTLN isOdd // Displays "TRUE"NEW INT a = 5
NEW INT b = 3
NEW INT c = 4
NEW BOOL unequal = ( a + b ) != ( c * 2 )
PRINTLN unequal // Displays "FALSE" ( 8 == 8 )NEW INT x = 5
NEW BOOL inRange = ( x != 0 ) && ( x != 10 )
PRINTLN inRange // Displays "TRUE"NEW STR grade = "B"
NEW BOOL notTopOrBottom = ( grade != "A" ) && ( grade != "F" )
PRINTLN notTopOrBottom // Displays "TRUE"NEW STR status = "pending"
NEW BOOL needsAction = ( status != "complete" ) || ( status != "cancelled" )
PRINTLN needsAction // Displays "TRUE"Is Not Equal To is the logical opposite of Is Equal To. Any comparison that is True with == will be False with !=, and vice versa.
NEW INT x = 5
NEW INT y = 10
PRINTLN x == y // Displays "FALSE"
PRINTLN x != y // Displays "TRUE"
NEW INT z = 5
PRINTLN x == z // Displays "TRUE"
PRINTLN x != z // Displays "FALSE"NEW INT age = 0
IF age != 0
PRINTLN "Valid age: " .. age
ELSE
PRINTLN "Please enter your age"
END IF
// Displays "Please enter your age"NEW STR role = "user"
IF role != "admin"
PRINTLN "Access restricted"
ELSE
PRINTLN "Access granted"
END IF
// Displays "Access restricted"NEW INT counter = 5
WHILE counter != 0
PRINTLN "Count: " .. counter
SET counter = counter - 1
END WHILE
PRINTLN "Finished!"
// Displays: Count: 5, Count: 4, Count: 3, Count: 2, Count: 1, Finished!NEW INT i = 1
WHILE i <= 5
IF i != 3
PRINTLN "Processing item " .. i
ELSE
PRINTLN "Skipping item " .. i
END IF
SET i = i + 1
END WHILE
// Displays all items, skipping item 3NEW STR word1 = "Hello"
NEW STR word2 = "hello"
PRINTLN word1 != word2 // Displays "TRUE" ( case makes them different! )
PRINTLN word1 != "Hello" // Displays "FALSE"NEW INT x = 5
NEW INT y = 10
// Using Is Not Equal To
NEW BOOL different1 = x != y
// Using NOT with Is Equal To ( requires parentheses in expressions )
// Note: ProtoLang doesn't have a NOT operator in Version 1.0-beta
// So != is the direct way to check inequality
PRINTLN different1 // Displays "TRUE"NEW INT x = 5
NEW STR y = "5"
PRINTLN x != y // Type error! Cannot compare Integer and StringNEW INT x = 5
NEW FLOAT y = 5.0
PRINTLN x != y // Type error! Cannot compare Integer and FloatNEW INT x = 5
// Wrong: Trying to use != in assignment
// SET x != 10 // Syntax error!
// Correct: != is for comparison only
NEW BOOL isDifferent = x != 10
PRINTLN isDifferent // Displays "TRUE"NEW STR status = "ACTIVE"
IF status != "active" // Will be TRUE due to case difference
PRINTLN "Status is not active"
END IF
// Displays "Status is not active" even though intent was to match
// Correct: Match the case
IF status != "ACTIVE"
PRINTLN "Status is not active"
END IF