New Multi-Branched Condition: SWITCH

This topic(how-does-vardradic-if-else-if-work-with-list-inputs) inspire me: How can i make a variadic if then else ? (and how it can accept a list of conditions in the variadic arrows)

V1.0 (depreciated)

3 new blocks in this project (v1.0)
switch1
switch2
switch3

How it work:
image

example #1:
switch4

example #2 (a list of conditions in the variadic input):
switch5

There is an implicit "break" after running the conditionnal code (only the 1st true condition will be executed)

Same thing but with the actual Multi-Branched Condition Lib:
case if

New Version 1.2

3 new blocks in this project (v1.2):
switch1
switch2
switch3

How it work:

example #1:

What do you think of this ?

Looks good. Can you share the code?

Sorry, i always forgot... :upside_down_face:
Project

Thanks for sharing your code.
It works fine in most cases.

Just one remark ...

I slightly modified one of your test scripts:
switch v1 script pic

with:
switch v1 script pic (1)

Now as it turns out, even if the first condition is met, the second condition is apparently evaluated in the process, as indicated by five seconds of wait time. I don't suppose this is what you have been looking for..

Hint: evaluate the first condition first, then (depending on the result) either execute the first action, or use recursion to proceed with the second (and following) cases (don't forget to include a base case at the very start of the recursive function: if the list of conditions is empty, execute the default action and stop).

Thank you for testing it !

In this block version, i've try to avoid the for each block.

If I'm for using the "for each" block, maybe I'll implement the new version like in C language: with an optional break at the end of the conditional code

wikipedia :

Switch statement in C

switch (age) {
case 1: printf("You're one."); break;
case 2: printf("You're two."); break;
case 3: printf("You're three.");
case 4: printf("You're three or four."); break;
default: printf("You're not 1, 2, 3 or 4!");
}

Where is the code? :grinning:

It's the actual version...

No new version for now!

Here is the v1.2

What's new?

  • Break feature : stop/don't stop evaluating next conditions
  • Conditions are evaluated only if nessessary (thk qw23)