Asking questions, getting answers...

if and while are execution controllers that we will discuss in the next section. In this section we use the if command to explain questions.

A simple example of questions:

x = 6
if x > 5 [
  print "hello"
]
In this example the question is the x > 5 part. If the answer to this question is “true” the code between the brackets will be executed. Questions are an important part of programming and often used together with execution controllers, like if. All numbers and variables (number containers) can be compared to each other with questions.

Here are all possible questions:

Table 4.1. Types of questions

a == bequalsanswer is “true” if a equals b
a != bnot-equalanswer is “true” if a does not equal b
a > bgreater thananswer is “true” if a is greater than b
a < bsmaller thananswer is “true” if a is smaller than b
a >= bgreater than or equalsanswer is “true” if a is greater than or equals b
a <= bsmaller than or equalsanswer is “true” if a is smaller than or equals b

Questions can also be glued to each other with “question glue”, this way a few questions can become one big question.

a = 1
b = 5
if a < 5 and b == 5 [
  print "hello"
]
In this example the glue-word and is used to glue 2 questions (a < 5, b == 5) together. If one side of the and would answer “false” the whole question would answer “false”, because with the glue-word and both sides need to be “true” in order to answer “true”.

and is not the only glue-word there are two others. They are all in the next table:

Table 4.2. Question glue-words

andboth sides need to be “true” in order to answer “true”
orif one of the sides is “true” the answer is “true”
notonly if both of the sides are “false” the answer is “false”