[thelist] Switch statement

Chris W. Parker cparker at swatgear.com
Fri Jul 19 11:20:05 CDT 2002


i haven't used a switch in a long time but let me see if i can give a
good example of how it's useful.

(hopefully i'm doing this right and not being retarded. let's just say
this is pseudo-code in case the syntax is wrong. ;)

switch (hiscore) {
	case 100:
		addAGoldStarTo(jenny);
	case 90:
		addAGoldStarTo(jenny);
	case 80:
		addAGoldStarTo(jenny);
	case 70:
		addAGoldStarTo(jenny);
	case 60:
		addAGoldStarTo(jenny);
	case 50:
		addAGoldStarTo(jenny);
	case 40:
		//nothing
}

so that means that the higher the score 'jenny' gets, the more gold
stars she gets.

(i really hope i did that right.)

now i've got a question!

how do you do conditionals? iirc, you can't do 'case <= 40:' or can you?
i don't think so.

i just read (thanks to our good friend the google) that C# doesn't
require a break; statement and executes like VBScript? is this true?


chris.

> -----Original Message-----
> From: Joel Canfield [mailto:joel at spinhead.com]
> Sent: Friday, July 19, 2002 6:52 AM
> To: 'thelist at lists.evolt.org'
> Subject: RE: [thelist] Switch statement
>
>
> --
> [ Picked text/plain from multipart/alternative ]
> > > Break is needed, not
> > > only in JavaScript but other languages as well.
> >
> > Well, not in VBscript :)) And maybe that's why I'm a little
> > bit confused...
>
> Right. But aren't you comparing 'switch' to VBScript's 'case'
> ? In 'case' it
> will execute the code for only the matching case; but switch is a more
> powerful tool (I'm startin' to like this PHP stuff.) It allows you the
> choice to execute any or all cases, only exiting the group of
> cases when you
> choose to.
>
> joel
> --
> For unsubscribe and other options, including
> the Tip Harvester and archive of thelist go to:
> http://lists.evolt.org Workers of the Web, evolt !
>



More information about the thelist mailing list