Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Need help with ifs and cases structure!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Heyman123




PostPosted: Sun Jan 27, 2008 6:18 pm   Post subject: Need help with ifs and cases structure!

Can someone explain the difference between ifs and cases to me. Also the benefits of using each one specifically.
Sponsor
Sponsor
Sponsor
sponsor
ericfourfour




PostPosted: Sun Jan 27, 2008 6:43 pm   Post subject: RE:Need help with ifs and cases structure!

Use ifs when you are comparing more than one variable. Use cases when you are comparing different values of a specific variable.
Cervantes




PostPosted: Sun Jan 27, 2008 7:00 pm   Post subject: RE:Need help with ifs and cases structure!

case is really just a specific application of if. You can do everything you can do with case with if. Case just sometimes happens to provide a more compact notation for you.

Isn't it true that with case, you can only compare using equality? For example, you can't use case to compare your integer variable num to the values 5, 6, and anything greater than 6?
Clayton




PostPosted: Mon Jan 28, 2008 12:05 am   Post subject: RE:Need help with ifs and cases structure!

Cervantes is correct, however, it makes comparing a random integer much easier:

Turing:

case Rand.Int (1, 10) of
    label 1 :
        %blah
    label 2 :
        #bleh
    %etc etc
end case


as opposed to saving that value in some temporary variable and having to continually compare the value of it.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: