0
Is Odd or Even Function

/t5/coldfusion-discussions/is-odd-or-even-function/td-p/213472
Sep 24, 2008
Sep 24, 2008
Copy link to clipboard
Copied
Is there a way to take a number from the database and
determine weather or not it is odd or even?
I am listing a number of employees and I want to alternate the background color of the cells of the table housing their names on a webpage.
I am listing a number of employees and I want to alternate the background color of the cells of the table housing their names on a webpage.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/coldfusion-discussions/is-odd-or-even-function/m-p/213473#M19118
Sep 24, 2008
Sep 24, 2008
Copy link to clipboard
Copied
use MOD operator:
<cfif someintegervalue MOD 2 eq 0>
even
<cfelse>
odd
</cfif>
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
<cfif someintegervalue MOD 2 eq 0>
even
<cfelse>
odd
</cfif>
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Advocate
,
/t5/coldfusion-discussions/is-odd-or-even-function/m-p/213474#M19119
Sep 24, 2008
Sep 24, 2008
Copy link to clipboard
Copied
<cfif number mod 2 eq 0>
even
<cfelse>
odd
</cfif>
even
<cfelse>
odd
</cfif>
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/coldfusion-discussions/is-odd-or-even-function/m-p/213475#M19120
Sep 24, 2008
Sep 24, 2008
Copy link to clipboard
Copied
<cfoutput query="yourquery">
<tr bgcolor="#iif(CurrentRow mod 2, de(colour1), de(colour2))#">
<tr bgcolor="#iif(CurrentRow mod 2, de(colour1), de(colour2))#">
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/coldfusion-discussions/is-odd-or-even-function/m-p/213476#M19121
Sep 24, 2008
Sep 24, 2008
Copy link to clipboard
Copied
PopcornCoder wrote:
> Is there a way to take a number from the database and determine weather or not
> it is odd or even?
>
> I am listing a number of employees and I want to alternate the background
> color of the cells of the table housing their names on a webpage.
>
The mod operator can be used for this.
<cfif aValue MOD 2 eq 1>
aValue is ODD
<cfelse>
aValue is EVEN
</cfelse>
OR
<cfif aValue MOD 2 eq 0>
aValue is EVEN
<cfelse>
aValue is ODD
</cfelse>
> Is there a way to take a number from the database and determine weather or not
> it is odd or even?
>
> I am listing a number of employees and I want to alternate the background
> color of the cells of the table housing their names on a webpage.
>
The mod operator can be used for this.
<cfif aValue MOD 2 eq 1>
aValue is ODD
<cfelse>
aValue is EVEN
</cfelse>
OR
<cfif aValue MOD 2 eq 0>
aValue is EVEN
<cfelse>
aValue is ODD
</cfelse>
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/coldfusion-discussions/is-odd-or-even-function/m-p/213477#M19122
Sep 24, 2008
Sep 24, 2008
Copy link to clipboard
Copied
Just a note to Azadi, Kronin555 & Ian:
A "MOD 2" operation already resolves to a boolean, so the further
comparison to 0 or 1 is not necessary.
{code}
<cfif i mod 2>
odd
<cfelse>
even
</cfif>
{code}
--
Adam
A "MOD 2" operation already resolves to a boolean, so the further
comparison to 0 or 1 is not necessary.
{code}
<cfif i mod 2>
odd
<cfelse>
even
</cfif>
{code}
--
Adam
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/coldfusion-discussions/is-odd-or-even-function/m-p/213478#M19123
Sep 24, 2008
Sep 24, 2008
Copy link to clipboard
Copied
Adam Cameron wrote:
> Just a note to Azadi, Kronin555 & Ian:
>
> A "MOD 2" operation already resolves to a boolean, so the further
> comparison to 0 or 1 is not necessary.
>
To be precise... since it is lunch time on the Pacific coast... I am
very hungry... I only have an Maruchan 'Instant Lunch' cup of noodles to
eat... And thus I am in a bit of an argumentative mood...
Thanks to ColdFusion typeless nature the results of a "MOD 2" operation
can be reliably converted to a boolean.
But some do not care to code with this implicit conversion so they like
to be explicit with their comparisons.
Also, as I *KNOW* you are fully aware of Adam, it could be confusing to
somebody who has not been exposed to the MOD operator before and thus
may not be clear on what it does. Thus such person should really read
the documentation on what MOD does! ;-)
> Just a note to Azadi, Kronin555 & Ian:
>
> A "MOD 2" operation already resolves to a boolean, so the further
> comparison to 0 or 1 is not necessary.
>
To be precise... since it is lunch time on the Pacific coast... I am
very hungry... I only have an Maruchan 'Instant Lunch' cup of noodles to
eat... And thus I am in a bit of an argumentative mood...
Thanks to ColdFusion typeless nature the results of a "MOD 2" operation
can be reliably converted to a boolean.
But some do not care to code with this implicit conversion so they like
to be explicit with their comparisons.
Also, as I *KNOW* you are fully aware of Adam, it could be confusing to
somebody who has not been exposed to the MOD operator before and thus
may not be clear on what it does. Thus such person should really read
the documentation on what MOD does! ;-)
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Advocate
,
/t5/coldfusion-discussions/is-odd-or-even-function/m-p/213479#M19124
Sep 24, 2008
Sep 24, 2008
Copy link to clipboard
Copied
quote:
Thanks to ColdFusion typeless nature the results of a "MOD 2" operation
can be reliably converted to a boolean.
But some do not care to code with this implicit conversion so they like
to be explicit with their comparisons.
Actually, CF will let you treat any integer as a boolean. Any non-zero number is True. Zero is false.
<cfoutput>
<cfloop from="-10" to="10" index="idx">
#idx#: <cfif idx>True<cfelse>False</cfif><br>
</cfloop>
</cfoutput>
This lets you do some interesting things:
<cfset reallytrue = true + true>
#reallytrue#
<cfset maybetrue = false + true>
#maybetrue#
Explicitly testing for mod 2 eq 0 is, in my mind, much clearer, easier for other coders to understand, and thus more beneficial.
<cfif intval mod 2>
What values get into this if?
<cfif intval mod 2 eq 0>
At least here, we're told, in the code, that any values divisible by 2 with no remainder will pass this if test.
Coldfusion's typeless nature is nice sometimes, but it's always better to be explicit, in my opinion.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/coldfusion-discussions/is-odd-or-even-function/m-p/213480#M19125
Sep 25, 2008
Sep 25, 2008
Copy link to clipboard
Copied
> Explicitly testing for mod 2 eq 0 is, in my mind, much
clearer, easier for
> other coders to understand, and thus more beneficial.
Firstly: I was just adding an observation, not condemning what any of you
did. Ian seemed to take (slight) umbrage at it.
I actually think the non-double-up of boolean evaluations is clearer, but
hey: I guess mileage varies.
> <cfif intval mod 2>
> What values get into this if?
> <cfif intval mod 2 eq 0>
> At least here, we're told, in the code, that any values divisible by 2 with no
> remainder will pass this if test.
I think this assertion is a bit specious. If someone doesn't know what x
MOD 2 can return, they've got far more problems ahead of them than how to
interpret a simple IF statement. However I guess one leads to t'other, so
fair cop.
Anyway... one can do either, and obviously opinions vary as to which is
better / clearer.
--
Adam
> other coders to understand, and thus more beneficial.
Firstly: I was just adding an observation, not condemning what any of you
did. Ian seemed to take (slight) umbrage at it.
I actually think the non-double-up of boolean evaluations is clearer, but
hey: I guess mileage varies.
> <cfif intval mod 2>
> What values get into this if?
> <cfif intval mod 2 eq 0>
> At least here, we're told, in the code, that any values divisible by 2 with no
> remainder will pass this if test.
I think this assertion is a bit specious. If someone doesn't know what x
MOD 2 can return, they've got far more problems ahead of them than how to
interpret a simple IF statement. However I guess one leads to t'other, so
fair cop.
Anyway... one can do either, and obviously opinions vary as to which is
better / clearer.
--
Adam
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/coldfusion-discussions/is-odd-or-even-function/m-p/213481#M19126
Sep 25, 2008
Sep 25, 2008
Copy link to clipboard
Copied
Adam Cameron wrote:
> Firstly: I was just adding an observation, not condemning what any of you
> did. Ian seemed to take (slight) umbrage at it.
Nah... If anything I was taking slight umbrage at the paucity of my
lunch yesterday. Taking it out on the world, or at least this forum, by
just being very explicitly strict in the interpretation of what actually
happens in ColdFusion under the hood.
And poking a bit at Adam that he did not, for once, point out the
documentation for MOD.
Otherwise I agree with Adam and personally I code with the implicit
conversation, but I understand the arguments for the other way as well.
> Firstly: I was just adding an observation, not condemning what any of you
> did. Ian seemed to take (slight) umbrage at it.
Nah... If anything I was taking slight umbrage at the paucity of my
lunch yesterday. Taking it out on the world, or at least this forum, by
just being very explicitly strict in the interpretation of what actually
happens in ColdFusion under the hood.
And poking a bit at Adam that he did not, for once, point out the
documentation for MOD.
Otherwise I agree with Adam and personally I code with the implicit
conversation, but I understand the arguments for the other way as well.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
LATEST
/t5/coldfusion-discussions/is-odd-or-even-function/m-p/213482#M19127
Sep 26, 2008
Sep 26, 2008
Copy link to clipboard
Copied
> Adam Cameron wrote:
>> Firstly: I was just adding an observation, not condemning what any of you
>> did. Ian seemed to take (slight) umbrage at it.
>
> Nah... If anything I was taking slight umbrage at the paucity of my
> lunch yesterday.
Well I hope you've learned your lesson from that? It can't be as bad as my
experience though. I went up to the pub for lunch, and the bloody thing
was closed! Grumble. But anyway.
> And poking a bit at Adam that he did not, for once, point out the
> documentation for MOD.
What, these ones?
http://livedocs.adobe.com/coldfusion/8/Expressions_03.html
;-)
If I'm the first person to respond to someone, I'll point them to the docs
if I think they haven't taken the time to look it up for themselves and the
documentation would explain something at least as well as I could. But in
this case a bunch of you had already explained it well enough, so a "RTFM"
suggestion would have been of little value.
I mean this as no comment against the OP in particular, but is it just me
or are the number of questions being asked here that stem from a basic lack
of effort in finding out the answer for one's self (ie: RTFM, Google,
simply engaging one's brain) on the increase? Oh well.
--
Adam
>> Firstly: I was just adding an observation, not condemning what any of you
>> did. Ian seemed to take (slight) umbrage at it.
>
> Nah... If anything I was taking slight umbrage at the paucity of my
> lunch yesterday.
Well I hope you've learned your lesson from that? It can't be as bad as my
experience though. I went up to the pub for lunch, and the bloody thing
was closed! Grumble. But anyway.
> And poking a bit at Adam that he did not, for once, point out the
> documentation for MOD.
What, these ones?
http://livedocs.adobe.com/coldfusion/8/Expressions_03.html
;-)
If I'm the first person to respond to someone, I'll point them to the docs
if I think they haven't taken the time to look it up for themselves and the
documentation would explain something at least as well as I could. But in
this case a bunch of you had already explained it well enough, so a "RTFM"
suggestion would have been of little value.
I mean this as no comment against the OP in particular, but is it just me
or are the number of questions being asked here that stem from a basic lack
of effort in finding out the answer for one's self (ie: RTFM, Google,
simply engaging one's brain) on the increase? Oh well.
--
Adam
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

