
-----------------------------------
FeniX
Fri Jun 20, 2003 8:50 am

Request - Can someone post a example of case selection?
-----------------------------------
If I am correct case selection has to do with if statements right?
well thank you to whoever posts an example.

-----------------------------------
Andy
Fri Jun 20, 2003 9:47 am


-----------------------------------
ya ur rite, its a simple way to do if statements

-----------------------------------
krishon
Fri Jun 20, 2003 9:53 am


-----------------------------------
yah..for example


var char : string

put "Enter a letter grade."
get char

case char of:

 label "A"
   put "Good job"
 label "B"
   put "Nice work, your almost there."
 label "C"
   put "That's ok, try harder."
 label "D"
   put "You have to get your act into gear quick."
 label "F"
   put "Your a failure."
 label ""
   put "You entered an invalid grade, try again."
end case

its somethin like this, i forgot the format cuz i haven't used it in a while

-----------------------------------
Andy
Fri Jun 20, 2003 9:56 am


-----------------------------------
that looks like Ti 83+ plus programming

-----------------------------------
krishon
Fri Jun 20, 2003 9:57 am


-----------------------------------
lol, TI 83+ programming is much worse...god it takes so long just to do a stupid quadratic formula program.

-----------------------------------
Andy
Wed Jun 25, 2003 11:43 am


-----------------------------------
no it doesn't... making a quadratic program is easy, making a factoring program takes a long time

-----------------------------------
naoki
Fri Jun 27, 2003 11:09 pm


-----------------------------------
case still sucks cuz it's getch. i'd prefer input.keydown myself

case is sorta easier 2 work with

-----------------------------------
AsianSensation
Sat Jun 28, 2003 9:59 am


-----------------------------------
case still sucks cuz it's getch. i'd prefer input.keydown myself

????????????
case = getch?
????????????

I always thought case was an alternate if thingie.

-----------------------------------
rizzix
Sat Jun 28, 2003 10:32 am


-----------------------------------
it is an alternate, but _restricted_, if statement syntax.
just a cosmetic feature of the language.

-----------------------------------
AsianSensation
Sat Jun 28, 2003 10:42 am


-----------------------------------
so why is case used if it is more restricted, and therefore, offers less options then if? Does it compile quicker or something? Or is it just more user friendly? (but if/then is very user friendly....I don't see how you can get more simpler by using case....)

-----------------------------------
SilverSprite
Sat Jun 28, 2003 12:18 pm


-----------------------------------
why do they have more than one type of operating system? its all about preference

-----------------------------------
naoki
Sat Jun 28, 2003 1:36 pm


-----------------------------------
get char 

case char of: 

label "A" 
   put "Good job" 

that's basically like getch in a sense (but more towards if statements).

-----------------------------------
Catalyst
Sat Jun 28, 2003 2:01 pm


-----------------------------------
it isnt like getch, its a basic language construct altho everything it does can be done using ifs and elsifs (or just ifs and elses for that matter)

-----------------------------------
PaddyLong
Sat Jun 28, 2003 2:25 pm


-----------------------------------
they are also very helpful in languages like Java where you don't have any elseif statement... just if and else...

so like you could have (not using java syntax, but the idea...)

if this = a then
  do this
else
  if this = b then
    do this
  else
    if this = c then
      do this
    end if
  end if
end if


or you could just have (not using java syntax, but the idea...)

case this of:
label a:
  do this 
label b:
  do this
label c:
  do this
end case


so probably it's in Turing to teach you (because as we all know, turing is just for learning to program  :roll: ) about them, so when you go to learn something like Java, you aren't like wtf is this??

-----------------------------------
Andy
Mon Jun 30, 2003 8:24 am


-----------------------------------
paddylong, is there no elsif in java?

-----------------------------------
PaddyLong
Mon Jun 30, 2003 11:44 am


-----------------------------------
no there's not... I said that in the post

-----------------------------------
SilverSprite
Mon Jun 30, 2003 5:54 pm


-----------------------------------
Well there really isnt an elsif on c++ either.. its just a compound of else and if statements.. or maybe i dont know what i'm talking about.. just something i noticed..

-----------------------------------
AsianSensation
Mon Jun 30, 2003 6:00 pm


-----------------------------------
when you say compound else and if, is that this?

if ()
blah blah blah
else if 
blah blah blah

so isn't that the same as elsif?

-----------------------------------
SilverSprite
Mon Jun 30, 2003 6:08 pm


-----------------------------------
you know how in c++ you dont need braces if you only have one line after if or elsif or anything else? and you can put it on the same line as the if or the elsif or the for loop etc..? so in c++


if (condition) //do this
else
{
if (condition) // do this
}

would be equivalent to 

if (condition) //do this
else if //do this

so the if after the else would actually be a seperate if on its own just placed on the same line as the else..

-----------------------------------
rizzix
Mon Jun 30, 2003 7:01 pm


-----------------------------------
yea it's equivalent to elsif in turing (for Java/C/C++/Objective-C/Perl/PHP/it goes on and on...)

don't worry, there is no drop in performance or anything as such. The Language designers (or what ever they are called probably Just Computer Scientists or Software Engineers) thought it is a better to have less unnecessary _keywords_ in a language thus making it compact, which i think is a good idea.
