Odd Even Numbers

Geoff Canyon gcanyon at inspiredlogic.com
Wed Feb 8 23:32:18 EST 2006


Using a function makes it easier to call from different places. isOdd  
is self-documenting, where inline code might not be. If error- 
detection code (checking that the value is a number, etc.) is  
necessary, putting it into a function once is better than adding it  
everywhere.

That said, there is overhead associated with calling a function, and  
this _is_ a very simple function. If it's being written for just this  
one application, then doing it inline is certainly an option.

gc

On Feb 8, 2006, at 8:27 AM, Jim Ault wrote:

> Rather than a function, why not use (assuming integer line numbers  
> only)
> get "blue"
> if x mod 2 = 0 then get "red"
> put it into colorChoice
>
> Jim Ault
> Las Vegas
>
> On 2/8/06 6:44 AM, "Geoff Canyon" <gcanyon at inspiredlogic.com> wrote:
>
>> function isOdd x
>>    if x mod 2 is 1 then return true else return false
>> end isOdd
>>
>> function isEven x
>>    if x mod 2 is 0 then return true else return false
>> end isEven
>>
>> Note that for these functions, 2.5 is neither odd nor even, and non-
>> numbers cause an error. To be safe you would use:
>>
>> function isOdd x
>>    if x is a number and x mod 2 is 1 then return true else return  
>> false
>> end isOdd
>>
>> function isEven x
>>    if x is a number and x mod 2 is 0 then return true else return  
>> false
>> end isEven
>>
>>
>> On Feb 8, 2006, at 6:28 AM, Robert Presender wrote:
>>
>>> How does one determine if a number is odd or even?
>>>
>>> For example I would like to do something like this:
>>>
>>> If the lineNumber of line x of fld "List" is odd then set the
>>> textColor to red.
>>>
>>> Suggestions are appreciated.
>>>
>>> Regards ... Bob
>
>
> _______________________________________________
> 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