jmeyer23288
26 days ago  Karma: 40
Why doesn't Solidity contain switch statments for control structures?

I realize that multiple If Else statments can be equvilant to a switch statment, but I assume this boils down to gas cost.

en
control structure
switch statement
jmeyer23288
26 days ago  Karma: 40
Why doesn't Solidity contain switch statments for control structures?

I realize that multiple If Else statments can be equvilant to a switch statment, but I assume this boils down to gas cost.

en
control structure
switch statement

ONE ANSWER
moinuddinbtech
25 days ago Karma: 156

It's not just switch, but even goto (though a not great practise) doesn't exist, but this is only till 0.4+ but with 0.5+ you can use switch. For more information you can look into this Switch in Solidity v0.5+

Remember, 0.4+ was for more part experimental, and because of backwards compatibility issues, they did not want to include anything that is breaking, and also something they want to drop in next major releases they only marked it as deprecated instead of altogether removing it.

It's not just switch, but even goto (though a not great practise) doesn't exist, but this is only till 0.4+ but with 0.5+ you can use switch. For more information you can look into this Switch in Solidity v0.5+

Remember, 0.4+ was for more part experimental, and because of backwards compatibility issues, they did not want to include anything that is breaking, and also something they want to drop in next major releases they only marked it as deprecated instead of altogether removing it.

Earn tokens by posting and answering questions about blockchain!
Karma to eth
YOUR ANSWER