cfloop from="1" to="6" index="i"
cfoutput#i# - cfif i mod 2OddcfelseEven/cfifbr/cfoutput
/cfloop
i mod 2 gives you the remainder from dividing by 2. If there IS a remainder
- meaning i mod 2 is not equal to zero, and therefore "true" - then the
number is odd.
Dan
-Original
CFLOOP Index = "Number" FROM = 1 TO = 6 STEP = 1
CFOUTPUT #Number#
-
CFSET IsOdd = (#Number#)Mod(2)
CFIF IsOdd EQ 0
This number is even
CFELSE
This number is odd
/cfif
brbr
/CFOUTPUT
/CFLOOP
-Original Message-
From: Jason Larson [mailto:[EMAIL PROTECTED]]
Sent: Monday, November
Use the MOD function.
cfif number MOD 2 is 0
even
cfelse
odd
/cfif
HTH,
Howie
- Original Message -
From: "Jason Larson" [EMAIL PROTECTED]
To: "CF-Talk" [EMAIL PROTECTED]
Sent: Monday, November 20, 2000 10:57 AM
Subject: Finding an Odd Number
Can someone help me out?
I have a
cfif YOURNUMBER MOD 2 GT 0
this is an odd number
cfelse
this is an even number
/cfif
Evan
-Original Message-
From: Jason Larson [mailto:[EMAIL PROTECTED]]
Sent: Monday, November 20, 2000 10:58 AM
To: CF-Talk
Subject: Finding an Odd Number
Can someone help me
I have a cfloop that loops 6 times, I want to be able to be
able to output what loop number the current loop is on, and
tell if the number is even or odd.
You can use the MOD operator, in conjunction with the current loop iteration
value:
cfloop index="i" from="1" to="10"
Row
cfif #number# mod 2 eq 0
I'm even
cfelse
I'm odd
/cfif
I dont remember CF's mod operator, but I'm sure there is one.
At 08:57 AM 11/20/00 -0700, Jason Larson wrote:
Can someone help me out?
I have a cfloop that loops 6 times, I want to be able to be able to output
what loop
CFIF (x/2) eq Int(x/2)
!--- X is even ---
CFELSE
!--- X is odd ---
/CFIF
From: "Jason Larson" [EMAIL PROTECTED]
Reply-To: [EMAIL PROTECTED]
Date: Mon, 20 Nov 2000 08:57:34 -0700
To: CF-Talk [EMAIL PROTECTED]
Subject: Finding an Odd Number
Can someone help me out?
I have a
Theres 2 methods for doing it.
!--- Method #1 ---
cfloop index="count" from="1" to="6" step="1"
#count#
/cfloop
!--- Method #2 ---
cfset x="1"
cfloop index="count" from="1" to="6" step="1"
#x#
cfset x=x+1
/cfloop
Now just add a condition in there. It makes it easy since you know that you
Try the Mod() function. It returns the remainder of a division. Any even
number divided by 2 is 0 so
cfif LoopNumber mod 2 is 0
LoopNumber is even
cfelse
LoopNumber is not even (odd)
/cfif
==
I have a cfloop that loops 6 times, I want to be able to be able to output
Take a look at the MOD operator in CF help. Basically, if INDEX MOD 2 = 1,
then the number is odd.
-Original Message-
From: Jason Larson [mailto:[EMAIL PROTECTED]]
Sent: Monday, November 20, 2000 9:58 AM
To: CF-Talk
Subject: Finding an Odd Number
Can someone help me out?
I have a
use the mod operator.
if the mod(index divided by 2) is other than zero than the number is
odd.
cfloop index="index" from="1" to="6"
cfset modnum = index mod 2
cfif modnum neq 0
Oddbr
cfelse
Evenbr
/cfif
/cfloop
Increment a counter inside the loop, and check the value of counter MOD 2.
-Original Message-
From: Jason Larson [mailto:[EMAIL PROTECTED]]
Sent: Monday, November 20, 2000 9:58 AM
To: CF-Talk
Subject: Finding an Odd Number
Can someone help me out?
I have a cfloop that loops 6 times,
You want to use 'Mod' - can't find it in the help doco, but if you run the code below
you should be able to figure out whats happening
CFOUTPUT
CFLOOP FROM="1" TO="6" INDEX="i"
#i# is
CFIF i Mod 2
even
CFELSE
odd
/CFIF
BR
/CFLOOP
/CFOUTPUT
Bert
To find out if a number is Odd, use BitAnd()
BitAnd(nYourNumber,1)
If nYourNumber is Odd, BitAnd() will return 1, else it will return 0.
-Original Message-
From: Jason Larson [mailto:[EMAIL PROTECTED]]
Sent: Monday, November 20, 2000 7:58 AM
To: CF-Talk
Subject: Finding an Odd Number
Use the following code as an example, the function you should look at is MOD
cfloop from="1" to="6" index="currentnumber"
cfoutput
The number : #currentnumber# is cfif (currentnumber MOD
2)oddcfelseeven/cfifbr
/cfoutput
/cfloop
Justin
-Original Message-
From:
divide by 2
"Jason Larson" [EMAIL PROTECTED] wrote:
Can someone help me out?
I have a cfloop that loops 6 times, I want to be able to be able to output
what loop number the current loop is on, and tell if the number is even or
odd.
Any help would be greatly appreciated
Thanks
Jason Larson
If your loop is using a numeric index that is incrementing, use that
(assuming it starts at "1"), otherwise, set a counter variable to one before
the loop begins, then increment it on each pass. To detect whether it's odd
or even: CFIF counter_var MOD 2 IS 0 it's even CFELSE it's odd/cfif or
use
cfset thisnum =1
cfloop
cfif thisnum is 2do this/cfif
Blah Blah
cfset this num = #thisnum# + 1
/cfllop
- Original Message -
From: Jason Larson [EMAIL PROTECTED]
To: CF-Talk [EMAIL PROTECTED]
Sent: Monday, November 20, 2000 8:57 AM
Subject: Finding an Odd Number
Can someone help me
Use the MOD operator
An even Number will return a 0, and odd number will return a 1
Jason Larson wrote:
Can someone help me out?
I have a cfloop that loops 6 times, I want to be able to be able to output
what loop number the current loop is on, and tell if the number is even or
odd.
Pardon the possible duplicate post.
I prefer this method to the other solutions provided because it is a
standard style function.
To find out if a number is Odd, use BitAnd()
BitAnd(nYourNumber,1)
If nYourNumber is Odd, BitAnd() will return 1, else it will return 0.
-Original
Jason didn't say WHY he cared about even or odd, but if you want to use it
to make every other row a different color, a great "trick" is to include
the digits "0" and "1" in style class names and then use the MOD value to
pick which style without ever having to use CFIF
You just define style
21 matches
Mail list logo