Difference between CASE and IF statements
Can someone please explain the difference between CASE and IF statements. They seem pretty similar but I have to believe there is a subtle difference that will bite me in the butt.
Case is used to evaluate more then one condition where If is used to evaluate only one condition. By using several Ifs in a row you can replicate the functionality of Case but it is slower for the computer and harder to read for the programmer.
The two use nearly identical syntax.
Case allows the evaluation of multiple boolean expressions (conditions) with an outcome for each and an outcome if none of the expressions evaluate as "true". It will return the value of the expression paired with the first boolean expression to evaluate to true.
If permits just one boolean expression with an outcome for true and and an outcome for false.
If ( A = b ; Value if True ; value If False )
Case ( A = b ; Value if A = B ; C = D ; Value if C = D ; E = G ; Value if E = G ; Value if none of the above are true )
Case ( A = b ; Value if True ; value if False )
has exactly the same results as IF. Thus many programmers prefer to use Case 100% of the time and do not use If at all. While I wouldn't get upset if a Future version of FileMaker discontinued If, since I do have IF, I prefer to use it in cases where there is only one boolean expression and reserve the use of Case for multiple boolean expressions--just a programming style that helps me see which situation applies in each place where I use the expression. If I find that I do need a second boolean expression, the process of converting an IF function into Case is a very trivial case of changing IF to Case and adding the additional expressions.
THanks for the answers
Retrieving data ...