2016-06-14 23:20:45 +02:00
|
|
|
# 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.
|
2016-06-14 23:20:45 +02:00
|
|
|
|
|
|
|
```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)
|
2016-06-14 23:20:45 +02:00
|
|
|
|