C# switch statement

81 views
Skip to first unread message

Giacomo Cecchinato

unread,
Dec 11, 2024, 11:18:41 AM12/11/24
to Blockly
As in the title, is there an implementation for the c# switch statement?

Aaron Dodson

unread,
Dec 11, 2024, 11:25:14 AM12/11/24
to Blockly
Hi,

We don't have a switch block in the core block library, but you could certainly create a custom block. The documentation for mutators will likely also be useful as you'd presumably want to be able to dynamically add and remove cases to a `switch` block much like else/elseif clauses in an `if` block.

- Aaron

Giacomo Cecchinato

unread,
Dec 12, 2024, 5:30:56 PM12/12/24
to Blockly
Hi Aaron, thanks for the quick answer. I was also thinking about something similar to the if/elseif block. Do you know if it possible to have a sample code of this block? I looked around but couldn't find anything similar. The manual is nice but a working example would be much more helpful.

Aaron Dodson

unread,
Dec 12, 2024, 5:34:31 PM12/12/24
to Blockly
Sure thing! The source for that block is available here: https://github.com/google/blockly/blob/develop/blocks/logic.ts#L49C1-L74C5 Note that most of the interesting parts are further down around here: https://github.com/google/blockly/blob/develop/blocks/logic.ts#L302-L562

Hopefully that helps - feel free to reach out if there are specific things you get stuck on!

- Aaron

fu6...@gmail.com

unread,
Dec 16, 2024, 6:42:55 AM12/16/24
to Blockly
Hi ,

I have previously written an Arduino C block in the old version of the Blockly development environment. I hope this example is helpful to you.

switch_block.png


Best wishes

fu6...

ado...@google.com 在 2024年12月13日 星期五清晨6:34:31 [UTC+8] 的信中寫道:
Reply all
Reply to author
Forward
0 new messages