Discuss Scratch
- Discussion Forums
- » Suggestions
- » Would it be possible to add the switch case, break and elseif control blocks?
- martinlaoshi
-
25 posts
Would it be possible to add the switch case, break and elseif control blocks?
Would it be possible to add the switch case, break and elseif control blocks?
Of course we can do without using the simple if .. else but those instructions are used by most of programming languages C, java, javascript, python …
I think for young people who approach programming with scratch, it would be fine to learn those instructions that they will see later when they will leave scratch for C, java or python.
In addition it make the code clearer and more readable.
For instance instead of
we will have : (with elseif instead of if for the 2nd 3rd 4th control)
Hope that's help!
Of course we can do without using the simple if .. else but those instructions are used by most of programming languages C, java, javascript, python …
I think for young people who approach programming with scratch, it would be fine to learn those instructions that they will see later when they will leave scratch for C, java or python.
In addition it make the code clearer and more readable.
For instance instead of
if <> then
else
if <> then
else
if <> then
else
if <> then
else
end
end
end
end
we will have : (with elseif instead of if for the 2nd 3rd 4th control)
if <> then
end
if <> then
end
if <> then
end
if <> then
end
Hope that's help!
- coder2045
-
1000+ posts
Would it be possible to add the switch case, break and elseif control blocks?
What does “switch case” and “break” do?
- DaEpikDude
-
1000+ posts
Would it be possible to add the switch case, break and elseif control blocks?
For switch case: if else if is added then IMO this is basically redundant. I can't think of a single time I've used switch case, casewhere or similar statements in any other programming language.
For else if: I'd support if if there was an easy and intuitive way to make them. For example if there was a sort of half-block that snapped onto the bottom of the existing if / if else block?
For break: I'd like it, but it would probably need a more intuitive name. Maybe “exit loop”?
“break” exits a loop before it's finished
For else if: I'd support if if there was an easy and intuitive way to make them. For example if there was a sort of half-block that snapped onto the bottom of the existing if / if else block?
For break: I'd like it, but it would probably need a more intuitive name. Maybe “exit loop”?
“switch case” is a multi-way selection where it takes some variable / value / whatever and compares it against certain conditions What does “switch case” and “break” do?
“break” exits a loop before it's finished
- martinlaoshi
-
25 posts
Would it be possible to add the switch case, break and elseif control blocks?
coder2045 wrote:
What does “switch case” and “break” do?
This is the basic use of switch case instruction in java
switch (variable) {
case value1 :
// code done when variable=value1
break;
case value2 :
// code done when variable=value2
break;
…
case valuen:
// code done when variable=valuen
break;
default:
// code done if none of the previous cases occured
}
Here is a workaround to use a switch case like coding in scratch : ( where break is a boolean variable)
set [ break] to [0]
if <<[variable] = [value1]> and <[break] = [0]>> then
// case value1 :
...
// code done when variable=value1
set [ break] to [1]
end
if <<[variable] = [value2]> and <[break] = [0]>> then
// case value2 :
...
// code done when variable=value2
set [ break] to [1]
end
...
if <<[variable] = [valuen]> and <[break] = [0]>> then
// case valuen :
...
// code done when variable=valuen
set [ break] to [1]
end
if <[break] = [0]> then
// default :
...
// code done if none of the previous cases occured
end
- ResExsention
-
1000+ posts
Would it be possible to add the switch case, break and elseif control blocks?
coder2045 wrote:
What does “switch case” and “break” do?
This is the basic use of switch case instruction in java
switch (variable) {
case value1 :
// code done when variable=value1
break;
case value2 :
// code done when variable=value2
break;
…
case valuen:
// code done when variable=valuen
break;
default:
// code done if none of the previous cases occured
}
Here is a workaround to use a switch case like coding in scratch : ( where break is a boolean variable)set [ break] to [0]
if <<[variable] = [value1]> and <[break] = [0]>> then
// case value1 :
...
// code done when variable=value1
set [ break] to [1]
end
if <<[variable] = [value2]> and <[break] = [0]>> then
// case value2 :
...
// code done when variable=value2
set [ break] to [1]
end
...
if <<[variable] = [valuen]> and <[break] = [0]>> then
// case valuen :
...
// code done when variable=valuen
set [ break] to [1]
end
if <[break] = [0]> then
// default :
...
// code done if none of the previous cases occured
end
That uses a variable though, which I'd rather not do.
Support for else if, but since case and switch are things I never use, no support for those.
Additionally, I support break, since it seems good for breaking out of loops before they finish execution.
- coder2045
-
1000+ posts
Would it be possible to add the switch case, break and elseif control blocks?
I don't get it.coder2045 wrote:
What does “switch case” and “break” do?
This is the basic use of switch case instruction in java
switch (variable) {
case value1 :
// code done when variable=value1
break;
case value2 :
// code done when variable=value2
break;
…
case valuen:
// code done when variable=valuen
break;
default:
// code done if none of the previous cases occured
}
Here is a workaround to use a switch case like coding in scratch : ( where break is a boolean variable)set [ break] to [0]
if <<[variable] = [value1]> and <[break] = [0]>> then
// case value1 :
...
// code done when variable=value1
set [ break] to [1]
end
if <<[variable] = [value2]> and <[break] = [0]>> then
// case value2 :
...
// code done when variable=value2
set [ break] to [1]
end
...
if <<[variable] = [valuen]> and <[break] = [0]>> then
// case valuen :
...
// code done when variable=valuen
set [ break] to [1]
end
if <[break] = [0]> then
// default :
...
// code done if none of the previous cases occured
end
- Sheep_maker
-
1000+ posts
Would it be possible to add the switch case, break and elseif control blocks?
In those languages, switch is like a fancy thing where you give it a value, then it skips to the point marked by the value, then it continues running code until it encounters “break,” where it then stops running the code inside the switch block.
Maybe these blocks?
However, since these blocks don't add any extra functionality to Scratch, and learners of those languages tend to grasp the concept of switch-case and else-if pretty easily, I don't think adding these to Scratch is necessary.
Maybe these blocks?
ask [What should I talk about?] and wait
jump to marker with (answer) {
marker [cows]::control
say [Cows are bad for the environment.]
exit jump to::control cap
marker [pigs]::control
say [Pigs are cool.]
exit jump to::control cap
if no markers match::control
say [I don't have an opinion on that.]
}::control
However, since these blocks don't add any extra functionality to Scratch, and learners of those languages tend to grasp the concept of switch-case and else-if pretty easily, I don't think adding these to Scratch is necessary.
- __Fyre__
-
23 posts
Would it be possible to add the switch case, break and elseif control blocks?
Maybe complicated conditionals could be some kind of extension In those languages, switch is like a fancy thing where you give it a value, then it skips to the point marked by the value, then it continues running code until it encounters “break,” where it then stops running the code inside the switch block.
Maybe these blocks?ask [What should I talk about?] and wait
jump to marker with (answer) {
marker [cows]::control
say [Cows are bad for the environment.]
exit jump to::control cap
marker [pigs]::control
say [Pigs are cool.]
exit jump to::control cap
if no markers match::control
say [I don't have an opinion on that.]
}::control
However, since these blocks don't add any extra functionality to Scratch, and learners of those languages tend to grasp the concept of switch-case and else-if pretty easily, I don't think adding these to Scratch is necessary.
- watashiwanekodesu
-
9 posts
Would it be possible to add the switch case, break and elseif control blocks?
edit: necropost
Last edited by watashiwanekodesu (April 11, 2022 19:56:09)
- Quantity08
-
60 posts
Would it be possible to add the switch case, break and elseif control blocks?
necroposts does not exist in suggestions form edit: necropost
- trebycode
-
13 posts
Would it be possible to add the switch case, break and elseif control blocks?
Hello, I do not mean to offend anybody but
the elseif block should be named to ifelse, just like ifthen.
I would also like to share with you my ideas.
the elseif block should be named to ifelse, just like ifthen.
I would also like to share with you my ideas.
- The “all at once” block/ “simultaneousy” block.
This block will do the things inside of it all at once and will be found in the control area. This is already possible with chrome extensions and such, so why cant we have it in regular scratch?
- More boolean stuff.
Right off the bat we need some more booleans. Like<When Message1 is broadcasted?>
(Thank you and goodbye.)
- k0d3rrr
-
1000+ posts
Would it be possible to add the switch case, break and elseif control blocks?
Necroposting only exists in the Suggestions forum if these two conditions are met:necroposts does not exist in suggestions form edit: necropost
1. The post has been made after a long time (most Scratchers believe this is usually one month or more)
2. The post is unconstructive (meaning it does not add anything to the discussion)
- Discussion Forums
- » Suggestions
-
» Would it be possible to add the switch case, break and elseif control blocks?