if condition


Feature introduction

The if block will run whatever code is inserted inside it, if the condition attached to the top of the block is fulfilled e.g. if button a pressed > set all rgb red

IF

  • if do The basic if block executes the code in the "do" position based on if the condition in the "if" position is met. The if section accepts the jigsaw puzzle shaped blocks such as button press event, maths and logic blocks or even sensor data from the units.

  • if else This if block allows us to run code if more than one condition is met. If the first condition is not met then it will default to whatever is placed in the "else" position. More conditions can be added by clicking the small cog on the if block and inserting "else if" blocks.

  • true Values of true or false (A.K.A "Boolean") can be used in the if condition to determine whether some predefined condition has been met. For example if you created a variable called game over and gave it the value True and placed this block in setup before the loop, and then used the = block in your if condition to check whether gameover is equal to true then the code placed next to "do" would run.

Usage

The if condition is highly necessary for any program of reasonable complexity, it allows the program to go in multiple directions based on events input by the user or some other predefined variable IF_user

results matching ""

    No results matching ""

    results matching ""

      No results matching ""