Discuss Scratch

martinlaoshi
Scratcher
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

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
Scratcher
1000+ posts

Would it be possible to add the switch case, break and elseif control blocks?

What does “switch case” and “break” do?
DaEpikDude
Scratcher
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”?

coder2045 wrote:

What does “switch case” and “break” do?
“switch case” is a multi-way selection where it takes some variable / value / whatever and compares it against certain conditions
“break” exits a loop before it's finished
martinlaoshi
Scratcher
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
New Scratcher
1000+ posts

Would it be possible to add the switch case, break and elseif control blocks?

martinlaoshi wrote:

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
Scratcher
1000+ posts

Would it be possible to add the switch case, break and elseif control blocks?

martinlaoshi wrote:

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
I don't get it.
Sheep_maker
Scratcher
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?
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__
Scratcher
23 posts

Would it be possible to add the switch case, break and elseif control blocks?

Sheep_maker wrote:

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.
Maybe complicated conditionals could be some kind of extension
watashiwanekodesu
New Scratcher
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
Scratcher
60 posts

Would it be possible to add the switch case, break and elseif control blocks?

watashiwanekodesu wrote:

edit: necropost
necroposts does not exist in suggestions form
trebycode
Scratcher
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 “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?>
There are so many others that I haven't thought about yet.

(Thank you and goodbye.)
k0d3rrr
Scratcher
1000+ posts

Would it be possible to add the switch case, break and elseif control blocks?

Quantity08 wrote:

watashiwanekodesu wrote:

edit: necropost
necroposts does not exist in suggestions form
Necroposting only exists in the Suggestions forum if these two conditions are met:

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)

Powered by DjangoBB