Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Infinite Loop!!!!

Status
Not open for further replies.

kosmokramer

Programmer
Sep 8, 2002
73
US
Can someone tell me what is wrong with this script? I keep getting an infinite loop.

//This is the calendar data.js file
if (null==dataSet) dataSet = new Array();

dataSet[dataSet.length] = "August";
dataSet[dataSet.length] = "Meeting ,1st,9:00,Hankamer";
dataSet[dataSet.length] = "Service Rush,5th,7:00,Place TBA";
dataSet[dataSet.length] = "Social Rush ,8th,6:00,Place TBA";
dataSet[dataSet.length] = "Informal Rush ,11th,8:00,Place TBA";
dataSet[dataSet.length] = "September";
dataSet[dataSet.length] = "Something Else,1st,9:00,Hankamer";
dataSet[dataSet.length] = "Another Thing ,5th,7:00,Place TBA";
dataSet[dataSet.length] = "Blah,8th,6:00,Place TBA";
dataSet[dataSet.length] = "eworuewr,11th,8:00,Place TBA";
dataSet[dataSet.length] = "October";
dataSet[dataSet.length] = "Meething 3,28th,9:00,Hankamer";
dataSet[dataSet.length] = "eworuewewrwe,5th,7:00,Place TBA";
dataSet[dataSet.length] = "Yet another thing,8th,6:00,Place TBA";
dataSet[dataSet.length] = "Something else 2,11th,8:00,Place TBA";

//This is the regular page
<html>
<head>
<script language=&quot;JavaScript&quot;>
var months = new makeArray(&quot;January&quot;,&quot;February&quot;,&quot;March&quot;,&quot;April&quot;,&quot;May&quot;,&quot;June&quot;,&quot;July&quot;,&quot;August&quot;,&quot;September&quot;,&quot;October&quot;,&quot;November&quot;,&quot;December&quot;);
var month = new Date()
var tempMonth = month.getMonth()

function makeArray() //This function just sets up the necessary space for the month array
{
for (var i = 0; i<makeArray.arguments.length; i++)
this = makeArray.arguments;
}


dataSet = new Array() //This is a seperate object. This is creating an array for use with the calendar data.js file
</script>

<script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot; src=&quot;calendar data.js&quot;></script>
</head>

<body>
<table border=0 cellpadding=0 width=65% style=&quot;margin-left:30pt&quot;>
<script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;>
//////////////////////////////////////////////////////////////
//This if statement writes out the table for the current month
//////////////////////////////////////////////////////////////
var doMonthLoop = false
var indexOfFirstMonth = dataSet.length;

document.write(&quot;doMonthLoop= &quot; + doMonthLoop + &quot;<br>&quot;); //Testing variables
document.write(&quot;IndexofFirstMonth= &quot; + indexOfFirstMonth + &quot;<br>&quot;);
document.write(&quot;dataset.length= &quot; + dataSet.length + &quot;<br>&quot;);
for(var n=0; n<dataSet.length || doMonthLoop == true; n++)
{
document.write(&quot;doMonthLoop2= &quot; + doMonthLoop + &quot;<br>&quot;); //Testing variables again
document.write(&quot;IndexofFirstMonth2= &quot; + indexOfFirstMonth + &quot;<br>&quot;);
document.write(&quot;dataset.length2= &quot; + dataSet.length + &quot;<br>&quot;);

if (dataSet[n] == months[tempMonth])
{
doMonthLoop = true
indexOfFirstMonth = n
}
}
document.write(&quot;doMonthLoop3= &quot; + doMonthLoop + &quot;<br>&quot;); //Third testing of variables
document.write(&quot;IndexofFirstMonth #3= &quot; + indexOfFirstMonth + &quot;&quot;);
if(doMonthLoop == true && indexOfFirstMonth != dataSet.length)
{
document.write(&quot;<tr>&quot; +
&quot;<td colspan=4 style=background:yellow height=36>&quot;+
&quot;<p>&quot; +
&quot;<font size=6><b>&quot; + dataSet[indexOfFirstMonth] + &quot;</b></font>&quot;+
&quot;</p>&quot; +
&quot;</td>&quot; +
&quot;</tr>&quot; +

&quot;<tr>&quot; +
&quot;<td style=background:#9999CC height=22>&quot;+
&quot;<u><font size=4><b>Event</b></font></u>&quot;+
&quot;</td>&quot; +

&quot;<td style=background:#9999CC height=22>&quot;+
&quot;<u><font size=4><b>Day</b></font></u>&quot;+
&quot;</td>&quot; +

&quot;<td style=background:#9999CC height=22>&quot;+
&quot;<u><font size=4><b>Time</b></font></u>&quot;+
&quot;</td>&quot; +

&quot;<td style=background:#9999CC height=22>&quot;+
&quot;<u><font size=4><b>Place</b></font></u>&quot;+
&quot;</td>&quot;+
&quot;</tr>&quot;);

for(var i=indexOfFirstMonth+1; i<dataSet.length && dataSet != months[tempMonth+1]; i++)
{
var tempString = dataSet .split(',');
if(i%2 == 1)
{
document.write(&quot;<tr>&quot;+
&quot;<td style=background:#CCCCFF height=19>&quot;+
tempString[0] +
&quot;</td>&quot;+

&quot;<td style=background:#CCCCFF height=19>&quot;+
tempString[1] +
&quot;</td>&quot;+

&quot;<td style=background:#CCCCFF height=19>&quot;+
tempString[2] +
&quot;</td>&quot;+

&quot;<td style=background:#CCCCFF height=19>&quot; +
tempString[3] +
&quot;</td>&quot; +
&quot;</tr>&quot;);
}
else
{
document.write(&quot;<tr>&quot;+
&quot;<td style=background:#9999CC height=19>&quot;+
tempString[0] +
&quot;</td>&quot;+

&quot;<td style=background:#9999CC height=19>&quot;+
tempString[1] +
&quot;</td>&quot;+

&quot;<td style=background:#9999CC height=19>&quot;+
tempString[2] +
&quot;</td>&quot;+

&quot;<td style=background:#9999CC height=19>&quot; +
tempString[3] +
&quot;</td>&quot; +
&quot;</tr>&quot;);
}
}
}
//////////////////////////////////////////////////////
//If it is not the current month, this will print out
//////////////////////////////////////////////////////
var doMonthLoop2 = false
var indexOfNextMonth = dataSet.length;

document.write(&quot;doMonthLoop2= &quot; + doMonthLoop + &quot;<br>&quot;); //These are testing variables
document.write(&quot;IndexofNextMonth= &quot; + indexOfNextMonth + &quot;<br>&quot;);
document.write(&quot;dataset.length= &quot; + dataSet.length + &quot;<br>&quot;);
for(var n=0; n<dataSet.length || doMonthLoop2 == false; n++)
{
document.write(&quot;doMonthLoop2 #2= &quot; + doMonthLoop2 + &quot;<br>&quot;); //Testing variables again
document.write(&quot;IndexofNextMonth2= &quot; + indexOfNextMonth + &quot;<br>&quot;);
document.write(&quot;dataset.length2= &quot; + dataSet.length + &quot;<br>&quot;);
if (dataSet[n] == months[tempMonth+1])
{
doMonthLoop2 = true
indexOfNextMonth = n
}
}
document.write(&quot;doMonthLoop2 #3= &quot; + doMonthLoop2 + &quot;<br>&quot;); //Third testing of variables
document.write(&quot;IndexofNextMonth3= &quot; + indexOfNextMonth + &quot;<br>&quot;);
document.write(&quot;dataset.length3= &quot; + dataSet.length + &quot;<br>&quot;);
if(doMonthLoop2 == true && indexOfNextMonth != dataSet.length)
{
document.write(&quot;<tr>&quot; +
&quot;<td colspan=4 style=background:yellow height=36>&quot;+
&quot;<p>&quot; +
&quot;<font size=6><b>&quot; + dataSet[indexOfNextMonth] + &quot;</b></font>&quot;+
&quot;</p>&quot; +
&quot;</td>&quot; +
&quot;</tr>&quot;);


for(var i=indexOfNextMonth+1; i<dataSet.length && dataSet != months[tempMonth+2]; i++)
{
var tempString2 = dataSet .split(',');
if(i%2 == 1)
{
document.write(&quot;<tr>&quot;+
&quot;<td style=background:#CCCCFF height=19>&quot;+
tempString2[0] +
&quot;</td>&quot;+

&quot;<td style=background:#CCCCFF height=19>&quot;+
tempString2[1] +
&quot;</td>&quot;+

&quot;<td style=background:#CCCCFF height=19>&quot;+
tempString2[2] +
&quot;</td>&quot;+

&quot;<td style=background:#CCCCFF height=19>&quot; +
tempString2[3] +
&quot;</td>&quot; +
&quot;</tr>&quot;);
}
else
{
document.write(&quot;<tr>&quot;+
&quot;<td style=background:#9999CC height=19>&quot;+
tempString2[0] +
&quot;</td>&quot;+

&quot;<td style=background:#9999CC height=19>&quot;+
tempString2[1] +
&quot;</td>&quot;+

&quot;<td style=background:#9999CC height=19>&quot;+
tempString2[2] +
&quot;</td>&quot;+

&quot;<td style=background:#9999CC height=19>&quot; +
tempString2[3] +
&quot;</td>&quot; +
&quot;</tr>&quot;);
}

}
document.write(&quot;<tr>&quot;+
&quot;<td style=background:#CCCCFF height=34>&quot;+
&quot;<p><span style=font-size:7.5pt>* FBC – on 5<sup>th</sup> St., Room #103<br>&quot;+
&quot;**Columbus Ave. Baptist Church Activities Center </span></p>&quot;+
&quot;</td>&quot;+

&quot;<td style=background:#CCCCFF height=34>&quot;+
&quot;</td>&quot;+

&quot;<td style=background:#CCCCFF height=34>&quot;+
&quot;</td>&quot;+

&quot;<td style=background:#CCCCFF height=34>&quot;+
&quot;</td>&quot;+
&quot;</tr>&quot;+
&quot;</table>&quot;)
}
else
{
document.write(&quot;<tr>&quot; +
&quot;<td colspan=4 style=background:yellow height=36>&quot;+
&quot;<p>&quot; +
&quot;<font size=6><b>There are no events currently scheduled!</b></font>&quot;+
&quot;</p>&quot; +
&quot;</td>&quot; +
&quot;</tr>&quot;+
&quot;</table>&quot;);
}
</script>

</body>
</html>
 
This looks like an infinite loop to me because if the doMonthLoop == true when this starts, nothing then sets it to false and so this will keep looping.


for(var n=0; n<dataSet.length || doMonthLoop == true; n++)
{
document.write(&quot;doMonthLoop2= &quot; + doMonthLoop + &quot;<br>&quot;); //Testing variables again
document.write(&quot;IndexofFirstMonth2= &quot; + indexOfFirstMonth + &quot;<br>&quot;);
document.write(&quot;dataset.length2= &quot; + dataSet.length + &quot;<br>&quot;);

if (dataSet[n] == months[tempMonth])
{
doMonthLoop = true
indexOfFirstMonth = n
}
}
 
Thanks. I tried that earlier actually, and it did not seem to work. I have tried all sorts of data in the calendar data.js file and with some it will work fine, but with others it keeps looping (for example if I have the currrent month, skip a month, and put in the following month).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top