-
Notifications
You must be signed in to change notification settings - Fork 1
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 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) { ...
Example:
if((a == 1) and (b == 2)) { ...
Logical OR results are true only if one of both operands are true. Alternatively to or
the ||
operator can be used (as in C).
Example:
if((a == 1) or (b == 2)) { ...
Comparison Operators can only be used in if
, for
, and while
condition.
Example:
import "stdio.asm"
func main() {
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--;
}
}