Computer Science Canada Case compared to If |
Author: | Tubs [ Tue Feb 25, 2003 11:01 am ] |
Post subject: | Case compared to If |
my first year of programming i was taught to use if statements to do the exact same thing as case statements. now i am introduced to case statements and told i have to use them in place of my old if statements, but i find that they are way less straightforward... what do you guys think? case or if? ex. var Choice : string put "blahblahblah".. get Choice if Choice = "blah" or Choice = "whatever else it may be" then %do whatever elsif .. end if compared to case label 1: label 2: etc |
Author: | Tony [ Tue Feb 25, 2003 3:02 pm ] | ||||
Post subject: | |||||
as far as I understand it, IF statments give you much more control over the situation. Such as you can write complex situations with AND, OR, NOT=, <, >, etc. Case statment just checks for the = statment, but it checks it for multiple values. Such as:
As you can see, it takes more lines to write out using IF statments, but they give you more control when you have to solve a complex statment like if (a=b and b=c and a not=d) or (d=e) then... try coding THAT using case statment |
Author: | Tubs [ Wed Feb 26, 2003 6:18 am ] |
Post subject: | |
i dont know any of the and or any if 'add-ons' yet. but i suspect i will this semester |
Author: | Tony [ Wed Feb 26, 2003 8:43 am ] | ||
Post subject: | |||
basically keywords and, or link more then 1 if statment to produce an overall result. such as
the program will output "swat is cool" only if both tony AND dan equal to "cool". If one of those statments return false, then the overall if statment is also false. |
Author: | Tubs [ Wed Feb 26, 2003 9:19 am ] |
Post subject: | |
so the and / or modifiers do the same thing |