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

Username:   Password: 
 RegisterRegister   
 Help switch statemnts??
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Sehroz




PostPosted: Sat Nov 03, 2007 2:38 pm   Post subject: Help switch statemnts??

Heyyy i have this project and i have to use " Switch statements" can anybody tell me wat tthat is??and how i use it ?? thanks greatly aprecaited XD
Sponsor
Sponsor
Sponsor
sponsor
CodeMonkey2000




PostPosted: Sat Nov 03, 2007 2:41 pm   Post subject: RE:Help switch statemnts??

You mean case construct?
Sehroz




PostPosted: Sat Nov 03, 2007 2:43 pm   Post subject: Re: Help switch statemnts??

yea its like i have the score for my game then i have to display a msg if the score is 25 or higher, 20 or higher etc and he said to use switch statments to give the user a qualitative message bases on hte users final score.
CodeMonkey2000




PostPosted: Sat Nov 03, 2007 2:47 pm   Post subject: Re: Help switch statemnts??

Straight out of the turing help file:
Turing Help File wrote:
case selection statement

Syntax A caseStatement is:
case expn of
{ label compileTimeExpn {, compileTimeExpn } :
statementsAndDeclarations }
[ label :
statementsAndDeclarations ]
end case



Description A case statement is used to choose among a set of statements (and declarations). One set is chosen and executed and then execution continues just beyond end case.
The expression (expn) following the keyword case is evaluated and used to select one of the alternatives (sets of declarations and statements) for execution. The selected alternative is the one having a label value equaling the case expression. If none are equal and there is a final label with no expression, that alternative is selected.


Example Output a message based on value of mark.

case mark of
label 9, 10 : put "Excellent"
label 7, 8 : put "Good"
label 6 : put "Fair"
label : put "Poor"
end case

Example Output a message based on value of name.

case name of
label "horse", "cow" : put "Farm animal"
label "tiger", "lion" : put "Jungle animal"
label "cat", "dog" : put "Pet"
label : put "Unknown animal"
end case

Details The case expression is required to match one of the labels. If it does not, there must be a final label with no expression. Label expressions must have values known at compile time. All label values must be distinct. The case expression and the label values must have the same equivalent type, which must be an integer, char, boolean, an enum type or strings.
Note that there is no way to express a range of values (for example from 5 to 10) in a label. Each individual value must be expressed in the label.


Sehroz




PostPosted: Sat Nov 03, 2007 2:50 pm   Post subject: Re: Help switch statemnts??

thankss but im a noob i dont understand wats the first sentece like to declare it like at the begging its var somthing : int etc?...
CodeMonkey2000




PostPosted: Sat Nov 03, 2007 3:11 pm   Post subject: Re: Help switch statemnts??

Consider this example:
Turing:
var input : string
get input

case input of %looks at the value of input

    label "foo" : %if the value of input is foo then...
        put "You said Foo!"
    label "bar", "Bar" : %if the value of input is bar or Bar then...
        put "you said Bar!"
    label : %if none of the above cases are true then...
        put "I don't understand"
end case
Sehroz




PostPosted: Sat Nov 03, 2007 8:05 pm   Post subject: Re: Help switch statemnts??

thankss Smile Very Happy it worked!!
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  [ 7 Posts ]
Jump to:   


Style:  
Search: