-
Notifications
You must be signed in to change notification settings - Fork 2
Comparison Operators
Compares the variable on the left with the value or variable on the right of the operator. Returns true when the two operands are not equal.
Example:
if(a != b) { ...
Compares the variable on the left with the value or variable on the right of the operator. Returns true when the left operand is less then the right one.
Example:
if(a < b) { ...
Compares the variable on the left with the value or variable on the right of the operator. Returns true when the left operand is is less than or equal to the right one.
Example:
if(a <= b) { ...
Compares the variable on the left with the value or variable on the right of the operator. Returns true when the two operands are equal.
Example:
if(a == b) { ...
Compares the variable on the left with the value or variable on the right of the operator. Returns true when the left operand is greater than the right one.
Example:
if(a > b) { ...
Compares the variable on the left with the value or variable on the right of the operator. Returns true when the left operand is greater than or equal to the right one.
Example:
if(a >= b) { ...
Comparison Operators can only be used in if
, for
, and while
condition.
Example:
import "stdio.asm"
func init() {
var a = 1;
var b = 2;
var i;
if(a == 0) {
putstr("ok");
} else {
putstr("error");
}
if(b == 2) {
putstr("ok");
} else {
putstr("error");
}
for(i = 0; i < 10; i++) {
putnum(i);
}
i = 10;
while(i > 0) {
putnum(i);
i--;
}
}