This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2009-12-19 16:17:01

Midlandman
Scratcher
Registered: 2007-06-28
Posts: 4

Case statement (a super-powered 'if')

Has anyone ever suggested a new control block, 'Case'?

There are many times when I have many 'ifs' one after the other, which are basically all checking the result of just one test and then selecting one out of set of different actions.

A 'Case' statement would really tidy this up.

<Case[test_something]>
   <when> result1 do action1
   <when> result2 do action2
   <when> result3  do action3
<end-case>

Offline

 

#2 2009-12-19 16:22:30

BWOG
Scratcher
Registered: 2008-09-19
Posts: 1000+

Re: Case statement (a super-powered 'if')

That would be nice. But you could also just put an If else block inside the else section of another one.

Offline

 

#3 2009-12-19 16:34:35

Midlandman
Scratcher
Registered: 2007-06-28
Posts: 4

Re: Case statement (a super-powered 'if')

Yes, but then you have to keep repeating the test in EVERY if!
The whole point of a 'Case' statement is that the test, (epecially a long and complex one), is programmed once and then each of the 'when' statements just checks for the results. ;-)

Offline

 

#4 2009-12-19 16:52:58

fg123
Scratcher
Registered: 2008-11-13
Posts: 1000+

Re: Case statement (a super-powered 'if')

Support. And it is an awesome idea! Doing
if
else
  if
  else
    if
    else

so on is very tiring and untidy.  smile


Hai.

Offline

 

#5 2009-12-19 17:34:12

JSO
Community Moderator
Registered: 2007-06-23
Posts: 1000+

Re: Case statement (a super-powered 'if')

I totally support this idea. Many programming languages have select-case or switch-case structures and Scratch focuses on learning programming. And there's plenty of room for improvement on the controls section  smile

Screenshot!
http://img687.imageshack.us/img687/3227/selectcasemockup.png
That would be so cool!

EDIT: From the third 'case' a  '-' sign should be shown to remove it again.

Last edited by JSO (2009-12-19 17:35:54)


http://oi48.tinypic.com/2v1q0e9.jpg

Offline

 

#6 2009-12-19 17:40:30

The-Whiz
Scratcher
Registered: 2007-07-09
Posts: 1000+

Re: Case statement (a super-powered 'if')

JSO wrote:

I totally support this idea. Many programming languages have select-case or switch-case structures and Scratch focuses on learning programming. And there's plenty of room for improvement on the controls section  smile

Screenshot!
http://img687.imageshack.us/img687/3227 … mockup.png
That would be so cool!

EDIT: From the third 'case' a  '-' sign should be shown to remove it again.

So if the input in the first case statement was "1", then the block would do the action inside of that?

Offline

 

#7 2009-12-19 17:42:48

cheddargirl
Scratch Team
Registered: 2008-09-15
Posts: 1000+

Re: Case statement (a super-powered 'if')

I would love to see a 'case' block in Scratch. I support this idea.  smile


http://i.imgur.com/8QRYx.png
Everything is better when you add a little cheddar, because when you have cheese your life is at ease  smile

Offline

 

#8 2009-12-19 17:46:20

JSO
Community Moderator
Registered: 2007-06-23
Posts: 1000+

Re: Case statement (a super-powered 'if')

The-Whiz - Yup  smile

http://en.wikipedia.org/wiki/Switch_statement

This is about the Switch statement (Switch-case), which is the same as Select-case.
Select seems a better name for use in Scratch because "select" describes it better then "switch" does when learning programming.


http://oi48.tinypic.com/2v1q0e9.jpg

Offline

 

#9 2009-12-19 22:05:20

Dibbo222
Scratcher
Registered: 2007-11-03
Posts: 100+

Re: Case statement (a super-powered 'if')

I support.


The biggest tower defense game on Scratch?
http://scratch.mit.edu/projects/Dibbo222/929092

Offline

 

#10 2009-12-20 01:03:36

Jonathanpb
Scratcher
Registered: 2008-07-25
Posts: 1000+

Re: Case statement (a super-powered 'if')

I support this.  smile

JSO: Good logical reasoning.  big_smile


"Human beings... must have action; and they will make it if they cannot find it.
-Charlotte Brontë

Offline

 

#11 2009-12-20 11:46:57

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Case statement (a super-powered 'if')

I remember asking for this sort of thing in v1.1. Its not the top priority but it would help speed some things up.


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

Board footer