Case Statement Help Needed
Author |
Message |
princess
|
Posted: 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
|
|
|
tum_twish
|
Posted: 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
|
Posted: 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)
|
|
|
|
|
|
|
|
|