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

Username:   Password: 
 RegisterRegister   
 Case Statement Help Needed
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
princess




PostPosted: Thu Jun 12, 2003 9:54 pm   Post subject: Case Statement Help Needed

ok... am i allowed to use array values in case statements??
if i am how do case statements work....
oh and wat is enum... cause that works in a case statement right??
Sponsor
Sponsor
Sponsor
sponsor
tum_twish




PostPosted: Fri Jun 13, 2003 10:06 am   Post subject: (No subject)

case <Expression> of

label <value>:

<Expressions>

[label...]

end case

Expressions are usually variables and values are the possible values of the variable

Sorry, I dont know enums
Prince




PostPosted: Fri Jun 13, 2003 10:48 am   Post subject: (No subject)

enum means enumerated type

code:

enum ( id { , id } )


The values of an enumerated type are distinct and increasing. They can be thought of as the values 0, 1, 2 and so on, but arithmetic is not allowed with these values.

code:

type color : enum ( red, green, blue )
var c : color := color . red
var d : color := succ ( c )        % d becomes green


Each value of an enumerated type is the name of the type followed by a dot followed by the the element's name, for example, color.red. Enumerated values can be compared for equality and for ordering. The succ and pred functions can be used to find the value following or preceding a given enumerated value. The ord function can be used to find the enumeration position of a value, for example, ord (color.red) is 0. Enumerated types cannot be combined with integers or with other enumerated types. In OOT, it is illegal to declare an "anonymous" enum. The only legal declaration for an enum is in a type declaration. For example, the following is now illegal:

code:

var a : array enum (red, green, blue ) of int


Given that there is no (easy) way of generating an enum value without it being a named type, this should not impact any but the most bizarre code. In OOT, the "put" and "get" statement semantics have been expanded to allow put's and get's of enum values. The values printed and input are the element names themselves, case sensitive. For example, for

code:
       
type colosr : enum ( red, green, blue )
var c : colors := colors . red
put c        % outputs "red" (without the quotes)
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  [ 3 Posts ]
Jump to:   


Style:  
Search: