Switch statement without break is not logical
Posted: Fri Nov 05, 2021 11:58 am
Hello all,
Not that I cannot do it differently with an If-Then but I think that the Switch statement workings are in my opinion not logical.
Of course, when using a break in a case the switch statement only performs the first case that is true. However, I would expect that without the break statement it would assess the next case and only executes the statements belonging to that case if the case is true.
Instead in the below setup it also does Answer B.
Do you think this is correct?
Regards,
MrCoolLion (or Paul)
Not that I cannot do it differently with an If-Then but I think that the Switch statement workings are in my opinion not logical.
Of course, when using a break in a case the switch statement only performs the first case that is true. However, I would expect that without the break statement it would assess the next case and only executes the statements belonging to that case if the case is true.
Instead in the below setup it also does Answer B.
Code: Select all
// Test Switch Case statement
put 1 into A
put 2 into B
Put 1 into C
switch
case A=1
answer "A = 1"
case B=1
answer "B = 1"
case C=1
answer "C = 1"
end switch
// Result: All cases are run also the B Case which should not run because the Case is not true.
Regards,
MrCoolLion (or Paul)