pxt-calliope/docs/reference/logic/if.md
2016-04-13 08:27:45 -07:00

30 lines
734 B
Markdown

# If
Run code based on a condition.
### @parent blocks/language
Conditionally run code depending on whether a [Boolean](/reference/types/boolean) condition is true or false.
### Block Editor
![](/static/mb/hourofcode-0.png)
In the Block Editor, click on the dark blue gear icon (see above) to add an *else* or *if* to the current block.
### Example: adjusting screen brightness
![](/static/mb/blocks/game-library/pic0.png)
If the screen [brightness](/reference/led/brightness) is `< 100`, this code sets the brightness to `255`:
### Lessons
[love meter](/lessons/love-meter), [zoomer](/lessons/zoomer)
### See also
[while loop](/reference/loops/while), [for](/reference/loops/for), [boolean](/reference/types/boolean)