Asking questions, getting answers...
Prev
Next

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.

Questions

A simple example of a question:

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 are highlighted with light blue in the code editor.

Question Glue

Question glue-words enable us to glue questions into 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”. Please do not forget to use the brackets around the questions!

Here is a schematic overview; a more detailed explanation follows below:

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'
notSpecial case: only works on one question! Changes 'true' into 'false' and 'false' into 'true'.

Question glue-words are highlighted with purple in the code editor.

and

When two questions are glued together with and, both sides of the and have to be 'true' in order to result in 'true'. An example:

a = 1
b = 5
if ((a < 10) and (b == 5)) and (a < b) [
  print "hello"
]
In this example you see a glued question glued onto an other question.

or

If one of the two questions that are glued together with or is 'true' the result will be 'true'. An example:

a = 1
b = 5
if ((a < 10) or (b == 10)) or (a == 0) [
  print "hello"
]
In this example you see a glued question glued onto an other question.

not

not is a special question glue-word because it only works for one question at the time. not changes 'true' into 'false' and 'false' into 'true'. An example:

a = 1
b = 5
if not ((a < 10) and (b == 5)) [
  print "hello"
]
else
[
  print "not hello ;-)"
]
In this example the glued question is 'true' yet the not changes it to 'false'. So in the end "not hello ;-)" is printed on the canvas.

Prev
Next
Home


Would you like to comment or contribute an update to this page?
Send feedback to the TDE Development Team