pxt-calliope/docs/blocks/logic/if.md
2016-06-15 07:55:19 -04:00

594 B

If

@parent blocks/language

Conditionally run code depending on whether a Boolean condition is true or false.

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

if(input.lightLevel()<100){
    led.setBrightness(255);
}

If the light level is < 100, this code sets the brightness to 255:

See also

while loop, for, boolean