From MakeCode to Circuit Python, an open text by students of Bates College and amazing people anywhere.
Makecode: There are also ways to format these statements with the blocks on makecode. For the if statements, you can select the Logic “if/ then statement” and fill in the blocks with your desired conditions and outputs. For example : “if x>0, set all lights to red.” You can also easily format the forever “while” loop in makecode, using the Loops block “forever.” Then, “if x>0, set all lights to red.”
Below is a link to a walk-through tutorial/ demonstrations of the material described above:
The video is slightly redundant when explaining make code- whereas in the video the If statement is demonstrated using the forever loop, it may have also been accomplished using the “on start” loop.
https://www.useloom.com/share/0961ef11174f483ea0ece5ba4544b399
A Boolean expression only has two possible values: it is true, or it is false. In its most simple sense, you can make a Boolean expression on make code using the blocks. Under the “Logic” heading, there is a “Boolean” subheading which contains “true” and “false” blocks. These can then be used to plug into any place a boolean value is expected.
When working with Boolean expressions, you can also use relational and logical operators. Relational operators compare the operands using =, <,>, >=, etc. Logical operators combine boolean expressions using “and”, “or”, and “not”. The relational operators can be found under the logic heading on makecode, under the subheading comparison. The “__and__”, “___or___”, and “not___” can also be found under the logic heading, under the subheading “Boolean.”
You can also use relational and logical operators in python, though in python they look a little different. When using relational operators, “==” is equal to, “!=” is not equal to, and “>, <, >=,” and “<=” are all as expected. For example, the operator “==” compares the operands to determine if they are equal (true) or unequal (false). An example of conditional operators in python would be “3 == 3 and 2 == 2.” AND dictates that BOTH must be true in order to be true and thus we would expect the output “true”. If one was not true, we would expect the output “false.” For another example we could use the logical operator “or.” If “4 > 2 or 1 > 2”, OR dictates that EITHER one or the other must be true, so in the case because the first operand is true, we would expect true.
A video demonstrating these concepts can be found below:
https://www.useloom.com/share/2493e4b0afb04a07a55cc2e3d1f03bde