Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Can someone explain % remainder?

Quote Reply
Can someone explain % remainder?
hi,

can someone explain to me how the logic for the % remainder works? ie. what does the following code do...

Code:
<%ifnot row_num % 3%>Hello<%endif%>

and can the % do tests like...

Code:
<%if row_num % 3 eq 1%>Hello<%endif%>

Thanks,
regan.
Quote Reply
Re: [ryel01] Can someone explain % remainder? In reply to
% is almost like "divisible by" for example:

<%set divisible = '5'%>

<%if divisible % 2%>
Foo
<%else%>
Bar
<%endif%>

...would print "Bar" because 5 doesn't divide by 2 without a remainder.

I don't think the parser will allow you to do things like <%if divisible % 2 == '1'%>

Last edited by:

Paul: Jun 14, 2002, 7:32 AM
Quote Reply
Re: [Paul] Can someone explain % remainder? In reply to
thanks for that paul!

one more for you - with the set feature, can you use it to add anohter variable that already exists? ie. inside a loop could you do this...

<%set newnum = row_num + '5'%>

doesn't seem to work for me but I might be doing it wrong. Unimpressed

regan.
Quote Reply
Re: [ryel01] Can someone explain % remainder? In reply to
Hi Regan,

The set isn't quite that powerful, but you can add a number to a variable.

You would have to write that as:

<%set newnum = $row_num%><%set newnum += 5%>

Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com