Comparing values
Each comparison answers true or false. Most have a symbol and a word you can use instead, whichever reads better.
| Write | Or | True when |
|---|---|---|
= | is | the two are the same |
<> | is not | they differ |
< > | less than, greater than | |
<= >= | at most, at least |
put 5 > 3
put 5 >= 5
put 5 <> 3
put 5 is not 3
put 5 = 5.0
put "cat" is "dog"
true true true true true false
Comparing text
Text is compared in alphabetical order, and xTalk does not mind capital letters unless you ask it to, with the property caseSensitive.
put "ABC" is "abc"
put "apple" < "banana"
set the caseSensitive to true
put "ABC" is "abc"
true true false
Is it in there?
xTalk has comparisons for text inside text that read like English. These are some of its most used words.
put "Hello world" contains "world"
put "world" is in "Hello world"
put "Hello world" begins with "Hell"
put "report.pdf" ends with ".pdf"
put "z" is not in "abc"
true true true true true
is among is stricter: it looks for a whole word, item or line, not just some characters.
put "b" is among the items of "a,b,c"
put "bc" is among the items of "a,b,c"
put "bc" is in "a,b,c"
put "fox" is among the words of "the quick brown fox"
put "Fri" is not among the items of "Sat,Sun"
true false false true true
And, or, not
Combine conditions with and (both must be true), or (at least one) and not (the opposite). Brackets make your meaning plain.
put 7 into tAge
put tAge >= 5 and tAge <= 12
put tAge < 5 or tAge > 65
put not (tAge = 7)
true false false
xTalk stops as soon as it knows the answer: if the left side of an and is false, the right side is never worked out. That lets you guard a test that would otherwise fail:
put 0 into tCount
if tCount > 0 and 100 / tCount > 10 then
put "Big share"
else
put "Nothing to share"
end if
Nothing to share
Try it yourself
A year is a leap year when it divides by 4, unless it divides by 100, except that one that divides by 400 is a leap year after all. Write one expression that puts whether tYear is a leap year, and try it with 1900 and 2000.
Show a solution
put 1900 into tYear
put (tYear mod 4 is 0 and tYear mod 100 is not 0) or tYear mod 400 is 0
put 2000 into tYear
put (tYear mod 4 is 0 and tYear mod 100 is not 0) or tYear mod 400 is 0
false true
Words in this lesson
Each one finds every lesson that uses it. The Dictionary has the whole story of each, with its syntax and more examples.