2016-03-26 00:47:20 +01:00
|
|
|
# If
|
|
|
|
|
|
|
|
### @parent blocks/language
|
|
|
|
|
|
|
|
|
2016-04-13 17:27:45 +02:00
|
|
|
Conditionally run code depending on whether a [Boolean](/reference/types/boolean) condition is true or false.
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2016-05-19 22:56:24 +02:00
|
|
|
```blocks
|
|
|
|
if(true) {
|
|
|
|
}
|
|
|
|
```
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2016-05-19 22:56:24 +02:00
|
|
|
```blocks
|
|
|
|
if(input.lightLevel()<100){
|
|
|
|
led.setBrightness(255);
|
|
|
|
}
|
|
|
|
```
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2016-05-19 22:56:24 +02:00
|
|
|
If the [light level](/input/light-level) is `< 100`, this code sets the brightness to `255`:
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
### See also
|
|
|
|
|
2016-04-13 17:27:45 +02:00
|
|
|
[while loop](/reference/loops/while), [for](/reference/loops/for), [boolean](/reference/types/boolean)
|
2016-03-26 00:47:20 +01:00
|
|
|
|