Re: IF <var> THEN
Posted in 1996
I have no problem with everything Mark writes here, except applying it to the question. As a matter of programming technique I would never (in any language) test for true/false on a variable that can contain other values. Of course it will work correctly in the excample given, I simply see it as a not so good practice, and it makes the code less clear. You have to know that 0 is false and any other value is true. A programmer shouldn't ever have to worry about such nastiness. Also, in 4GL, as a matter of technique, I would try all I can to avoid any test using <>. If the variable can ever be NULL you get problems. Of course sqlca.sqlcode isn't ever NULL, but this is again a matter of making things clear, consistent, and allways do things the same way. "Mark D. Stock" <marks@west.co.za> wrote: :Manel Falc' wrote: :> :> Is this expression correct ?: :> :> if SQLCA.SQLCODE then :> ... :> :> or it must be: :> :> if SQLCA.SQLCODE <> 0 then :> ... :> :> Which numeric types can we use with the first expression ?. :> It seems it is correct for smallint and integer types and :> I prefer it but I don't know if it is correct for all rapid/executable :> versions. :I take it you are referring to Informix-4GL and Informix-4GL RDS. :Both examples are correct. The first, IMO, is often more readable, :especially if the variable is named carefully. For example: : IF update_complete : THEN : ....continue : ELSE : ....we had an error : END IF :This form of the syntax requires the use of a BOOLEAN type. Now as :discussed on this group earlier, there IS NO BOOLEAN data type in :Informix. So you can use either SMALLINT or INTEGER. But why use :INT and waste 2bytes, when SMALLINT will do. :The boolean values then recognised by Informix in this context are: : 0 (zero) = FALSE : None-Zero = TRUE (this includes -ve numbers) :When initialising such variables you can use two system global variables :called TRUE and FALSE, which assign the values 1 (one) and 0 (zero) :respectivly. :The fact that -ve numbers are TRUE means that both your examples will work, :and both will work in all versions of Informix-4GL, whether RDS or fully- :compiled. Nils.Myklebust@idg.no <- New E-mail adress NM Data AS, P.O.Box 9090 Gronland, N-0133 Oslo, Norway My opinions are those of my company