Switch statements are better for several reasons.
First, they create a jump table that's slightly more efficient than the
if-then-else-if-then-else-if-then-else-etc.. method.
Secondly, and more importantly, it's generally easier to organize a bunch of 
options
into a switch statement than with a bunch of if-then-else blocks.

As for your damage, it kind of depends.
If they are all going to be arranged by blocks of 10, you might be able to do 
switch
(damage/10) or something.  Otherwise if-then-else is probably better.

Basically I go with whichever one makes for shorter code.

--Palrich.

----- Original Message ----- 
From: "Cyhawk" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Monday, January 05, 2004 5:47 PM
Subject: Question on Switches


> Hey all.
> Ok my question involves Switch statements.
> Lately, ive been writing switch statements because A) people tell me its
> better, and B) it makes more sense sometimes.
>
> Firstly, why are switches better?
>
> Second.. Im re-writing my damage messages (actually a whole new fight
> system, basicly the fight messages instead of Your slash DECIMATES bob!
> you get "Your sword deeply cuts bob" and so on depending on how much damage
> you do.)
> Basicly, if say i want case 1 - 10 to do one message, without typing them
> all out in each case?
>
> Any help is appreciated =)
>
> -Thri
>
>
> -- 
> ROM mailing list
> [email protected]
> http://www.rom.org/cgi-bin/mailman/listinfo/rom


Reply via email to