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
|
|
|
|
|
2016-12-19 23:09:35 +01:00
|
|
|
If the [light level](/reference/input/light-level) is `< 100`, this code sets the brightness to `255` when the button A is pressed:
|
|
|
|
|
2016-06-14 23:20:45 +02:00
|
|
|
```blocks
|
2016-12-19 23:09:35 +01:00
|
|
|
input.onButtonPressed(Button.A, () => {
|
|
|
|
if(input.lightLevel()<100){
|
|
|
|
led.setBrightness(255);
|
|
|
|
}
|
|
|
|
})
|
2016-06-14 23:20:45 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
### 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
|
|
|
|