nested ifs

simplsol at aol.com simplsol at aol.com
Wed Jan 25 13:14:14 EST 2006


Dave,
  The location of "then" is mostly personal preference. To me, this is 
more logical, consistent and easier to read:

 if....then... (for short statement, short response)

 if (long statement)
 then (long response)

 if
 then
 (lots of responses)
 end if

 if
 then
 1
 2
 3
 else
 1
 2
 end if

 if
then
      if
      then
      else
      end if
 else
      if
      then
      else
           if
           then
           end if
      end if
 end if

  No matter how many subconditionals there are, it is easy to see which 
statements and responses go together.
 Paul Looney

PS I hope that last example came over alright. Kind of meaningless if 
it is all flush left. If it got garbled, just paste it into a script 
and the script editor will align it properly.

 -----Original Message-----
 From: Dave Cragg <dcragg at lacscentre.co.uk>
  To: chipp at chipp.com; How to use Revolution 
<use-revolution at lists.runrev.com>
 Sent: Wed, 25 Jan 2006 17:21:06 +0000
 Subject: Re: nested ifs

 On 25 Jan 2006, at 10:32, Chipp Walters wrote: 
  
 > I like to do the following: 
 > 
 > if tResult is "Error" then 
 > answer "Go Ahead anyway" with "Cancel" or "OK" 
 > if it is "Cancel" then exit to top 
 > end if 
 > 
  > Most of the time it compiles, but sometimes the single line if > 
statement in the middle throws and error and won't compile, so I'm > 
forced to do: 
  
 The problem seems to occur before an "else" line. 
  
 If x > y then 
   doSomething1 
   if a = be then doSomething2 ##problem here 
 else 
   doSomethng3 
 end if 
  
  I've always assumed (without any deep investigation) that it was a 
result of the engine's tolerance of various "if" constructions. For 
example the following compiles: 
  
  if 1 > 2 then put 2 
  else put 1 
  
  While we're on the subject, could someone who likes to use the "then 
on the following line" syntax please explain the advantages. I've 
always found it confusing when I come across it, but there must be a 
reason for using it that I haven't yet grasped. 
  
 Cheers 
 Dave 
 _______________________________________________ 
 use-revolution mailing list 
 use-revolution at lists.runrev.com 
  Please visit this url to subscribe, unsubscribe and manage your 
subscription preferences: 
 http://lists.runrev.com/mailman/listinfo/use-revolution 

  



More information about the use-livecode mailing list