Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ SMAUG ➜ SMAUG coding ➜ A few questions.

A few questions.

It is now over 60 days since the last post. This thread is closed.     Refresh page


Pages: 1  2  3  4  5  6 

Posted by Meerclar   USA  (733 posts)  Bio
Date Reply #75 on Sun 26 Jun 2005 08:53 AM (UTC)

Amended on Sun 26 Jun 2005 09:01 AM (UTC) by Meerclar

Message
For lots cleaner code, you can do

case 1
found stuff message
case default
didnt find stuff message

Tends to be easier to read when you have all but 1 result with the same message. There's also the built in safety net of not crashing with a default if you somehow get a result not specified in your case struct.

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #76 on Sun 26 Jun 2005 08:40 PM (UTC)
Message
Or, you could just do:
if ( result == 1 )
  // found something
else
  // found nothing
The point of the case statement is really to save you from having to write out lots of if/else if/else if/... if you're just using two alternatives you may as well just use if/else. The compiler should be smart enough to not generate a jump table with a two-branch case statement but it doesn't hurt to help it out.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


222,514 views.

This is page 6, subject is 6 pages long:  [Previous page]  1  2  3  4  5  6 

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.