![]() | Asking questions, getting answers... |
Prev | KTurtle's Logo Programming Reference | Next |
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 == b | equals | answer is “true” if a equals b |
a != b | not-equal | answer is “true” if a does not equal b |
a > b | greater than | answer is “true” if a is greater than b |
a < b | smaller than | answer is “true” if a is smaller than b |
a >= b | greater than or equals | answer is “true” if a is greater than or equals b |
a <= b | smaller than or equals | answer 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
and | both sides need to be “true” in order to answer “true” |
or | if one of the sides is “true” the answer is “true” |
not | only if both of the sides are “false” the answer is “false” |
Prev | Home | Next |
Can the Turtle do math? | Up | Controlling execution |