pxt-calliope/docs/blocks/logic/if.md

29 lines
594 B
Markdown
Raw Normal View History

# If
### @parent blocks/language
2016-06-15 13:55:19 +02:00
Conditionally run code depending on whether a [Boolean](/blocks/logic/boolean) condition is true or false.
```blocks
if(true) {
}
```
Click on the dark blue gear icon (see above) to add an *else* or *if* to the current block.
### Example: adjusting screen brightness
```blocks
if(input.lightLevel()<100){
led.setBrightness(255);
}
```
If the [light level](/reference/input/light-level) is `< 100`, this code sets the brightness to `255`:
### See also
2016-06-15 13:55:19 +02:00
[while loop](/blocks/loops/while), [for](/blocks/loops/for), [boolean](/blocks/logic/boolean)