Discussion about 'if-else statement vs if-then statement' and Accelerometer

using 'If with multiple else' vs using 'if then' multiple times. Is there any difference in execution and output?

There is no difference in output.
The only reason why you would use if-else-if is if you wanted to do something when all the conditions that are already specified are not satisfied (these are handled under else), so you don't need to specify the condition again. This will save blocks, though the number depends on the complexity of the condition.

So, by adding more 'else' in a block we can avoid adding more 'if-then' blocks. am I right? Thankyou.

But, in this case we cannot easily copy paste the contents (we cannot duplicate all contents in single click) placed in 'else' incase if we need to copy paste somewhere in future.

@NishyanthKumar , Is there any benefit if we reduce/save blocks?

There is a big difference. Using multiple if blocks means that every condition test is run, regardless of the previous one. With if else if, the following tests will only run if the previous test was unsuccessful.

Keeping block count down always helps.


Is there a way to merge two if else blocks that contains lot of else with in. I created two if-else blocks, each if-else blocks contain more than 30 else blocks within. Each else blocks within contains lot of other blocks. Now, I wish to have only one if else block without loosing any blocks created. Is there a way to merge both if else blocks?

It is a drag and drop block builder. Drag and drop them.

I know that but it will be nice if there a feature to merge two blocks. This will be useful if the block contains lot of small blocks within. If we drag and drop each blocks that aee with in a big block, it may take 30 minutes or 1 hour if the size of the block is too big.

Instead, if there will be a feature in future to merge two blocks into one, in my case merging two if else blocks, then it will take only 1 or 2 seconds.

Drag the uppermost block, it will bring the blocks below with it.

1 Like

Okay, Il do it.

No, in if else block we cannot do it.

There is not an automatic way/procedure to join several "if - then" blocks into a one "if -then - else if - then..." block

Here I created a big if else block. I duplicated it. Now I want all the sub blocks in one if-else block. I want to make both into one block.

I hope mit will bring this feature in future.

Right now, I shall drag and drop each block. I think there will be around 200 small blocks within.

For a ladder this tall it's time to switch to a table lookup, like looping through a tax rate table.

(Yes, a long time ago I did my taxes manually)

1 Like

Can you say the same thing in different way? How can I switch to table look up?

What are the if then else tests?

Are you asking to share the blocks that I mentioned?

Have you learned procedures yet?

Yes share them

I attached the image here.

The image is unreadable.

Export the .aia file.

1 Like