Archive for the 'Programming' Category
Sub archives: Math
Ever wondered what modulo is? What it does? Why you would use it?
Simple. Modulo is the remainder of a division operation.
A few examples:
5 modulo 2 = 1 //Two goes into five twice, leaving a remainder of one
15 modulo 4 = 3 //Four goes into fifteen three times, leaving a remainder of three
Its that simple.
An example of using it? Designers often use modulo when designing the output of tables so they can alternate the colors on each row.
Languages including PHP and Java use the % sign.
An example:
for ($i=0; $i<10; $i++)
{
if ($i % 2)
{
//This is an even row
}
else
{
//This is an odd row
}
}
Remember, dividing by 2 will only ever have a remainder of 1 or 0.
Posted by OLLIE at 07:10am Permalink