473,398 Members | 2,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Having troubles understand Modulus

nomad
664 Expert 512MB
If I understand this right modules is used to divide a number and if there is a remainder that remainder is used?

here is part of a code that I'm trying to understand which produce part of a Calendar

[PHP]<?php
$days = Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
echo "<TABLE BORDER=1 CELLPADDING=5><tr>\n";
foreach ($days as $day) {
echo "<TD BGCOLOR=\"#CCCCCC\" ALIGN=CENTER><strong>$day</strong></td>\n";
}
for ($count=0; $count < (6*7); $count++) {
$dayArray = getdate($start);
if (($count % 7) == 0) {
if ($dayArray['mon'] != $month) {
break;
} else {
echo "</tr><tr>\n";
}
}
if ($count < $firstDayArray['wday'] || $dayArray['mon'] != $month) {
echo "<td>&nbsp;</td>\n";
} else {
echo "<td>".$dayArray['mday']." &nbsp;&nbsp; </td>\n";
$start += ADAY;
}
}
echo "</tr></table>";
?>[/PHP]


The part I'm trying to understand is
[PHP]if (($count % 7) == 0) {
if ($dayArray['mon'] != $month) {
break;
} else {
echo "</tr><tr>\n";
}[/PHP]

I know its trying to produce rolls for the week, but i just don't get it. I have read how its works several times. Question what is $count % 7) == 0 being divide by were does the variable $count gets it value from?

thanks

nomad

PS if you need more code I can give it out.
Aug 27 '08 #1
4 1454
Markus
6,050 Expert 4TB
It's saying (because '%' is used to find the remainder of a number') if the remainder of $count / 7 is 0 (ie, 7 goes into $count perfectly) then run the code.

Hope this helps.
Aug 27 '08 #2
nomad
664 Expert 512MB
It's saying (because '%' is used to find the remainder of a number') if the remainder of $count / 7 is 0 (ie, 7 goes into $count perfectly) then run the code.

Hope this helps.
I get that part but still trying to figure out where the number is coming from
for ($count=0; $count < (6*7); $count++) { // ie $count is the variable coming from the user from the pull down menu?

sorry new to this info.

nomad
Aug 27 '08 #3
Markus
6,050 Expert 4TB
I get that part but still trying to figure out where the number is coming from
for ($count=0; $count < (6*7); $count++) { // ie $count is the variable coming from the user from the pull down menu?

sorry new to this info.

nomad
No, count is 0 and then incremented in the for loop. Am I missing your problem? Haha.
Aug 27 '08 #4
Atli
5,058 Expert 4TB
Hi.

Check out for loops in the manual.

The $count variable, in your case, is created inside the for loop to keep track of the number of loops that have been executed.

You could re-write that for loop like so, as a while loop:
Expand|Select|Wrap|Line Numbers
  1. $count = 0;
  2. while ($count < 42) 
  3. {
  4.   // Do the loop code here
  5.  
  6.   $count ++;
  7. }
  8.  
The for loop syntax is just a shortcut, to make the code cleaner and easier to read.
Aug 28 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Kelly Vernon | last post by:
I have a standard ASP page that appends to an xml page. Currently if there is more than one person attempting to append to the same XML file at a time. One user will have the ability to append,...
10
by: jantod | last post by:
I think there might be something wrong with the implementation of modulus. Negative float values close to 0.0 break the identity "0 <= abs(a % b) < abs(b)". print 0.0 % 2.0 # => 0.0 print...
5
by: Peter Pippinger | last post by:
Hello NG, i need to calculate the modulus with double precisson typed variables. this works well with integers: w1 = w1 % 360; but what do i have to do if i want to use w1 as double? ...
4
by: tvnaidu | last post by:
How to calculate Prescalar and Modulus values for PIT (Programmable Interrupt Timer). I have microcontroller running at 60MHz. I am thinking of writing 1 milli sec ISR for PIT. I need to calculate...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.