Need help with ifs and cases structure!
Author |
Message |
Heyman123
|
Posted: Sun Jan 27, 2008 6:18 pm Post subject: Need help with ifs and cases structure! |
|
|
Can someone explain the difference between ifs and cases to me. Also the benefits of using each one specifically. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
ericfourfour
|
Posted: Sun Jan 27, 2008 6:43 pm Post subject: RE:Need help with ifs and cases structure! |
|
|
Use ifs when you are comparing more than one variable. Use cases when you are comparing different values of a specific variable. |
|
|
|
|
|
Cervantes
|
Posted: Sun Jan 27, 2008 7:00 pm Post subject: RE:Need help with ifs and cases structure! |
|
|
case is really just a specific application of if. You can do everything you can do with case with if. Case just sometimes happens to provide a more compact notation for you.
Isn't it true that with case, you can only compare using equality? For example, you can't use case to compare your integer variable num to the values 5, 6, and anything greater than 6? |
|
|
|
|
|
Clayton
|
Posted: Mon Jan 28, 2008 12:05 am Post subject: RE:Need help with ifs and cases structure! |
|
|
Cervantes is correct, however, it makes comparing a random integer much easier:
Turing: |
case Rand.Int (1, 10) of
label 1 :
%blah
label 2 :
#bleh
%etc etc
end case
|
as opposed to saving that value in some temporary variable and having to continually compare the value of it. |
|
|
|
|
|
|
|