While loop problems (Please Help)

Hey..
Got ova the time problem and its kno a while loop problem. It doesnt seam to want to keep goin and it only does it once i think. Any ways heres the code:

[code]

//General
var debug = "y";
var i = 0;
var oweek1 = "-";

//Make old vars
var odate = new Date(2004,6,20,0,0);
var oday = odate.getDate();
var omonth = odate.getMonth();
var oyear = odate.getYear();

//Make new vars
var ndate = new Date();
var nday = ndate.getDate();
var nmonth = ndate.getMonth();
nmonth++;
var nyear = ndate.getYear();

//debug
if (debug == "y")
{
document.writeln("General Vars
");
document.writeln(debug + "
");
document.writeln(i + "

");
document.writeln("Old Dates
");
document.writeln(oday + "
");
document.writeln(omonth + "
");
document.writeln(oyear + "
");
document.writeln(odate + "
");
document.writeln("
New Dates
");
document.writeln(nday + "
");
document.writeln(nmonth + "
");
document.writeln(nyear + "
");
}

//Find date

while(i=0,odate != ndate,i++)
{
//Debug
if(debug =="y")
{
document.writeln(i + "
");
document.writeln(oday + "
");
document.writeln(omonth + "
");
document.writeln(oyear + "
");
}

oday++;

//January
if(omonth == 1) and (oday == 31)
{
oday = 1;
omonth++;
}

//Febuary
if(omonth == 2) and (oday == 28)
{
oday = 1;
omonth++;
}
//March
if(omonth == 3) and (oday == 31)
{
oday = 1;
omonth++;
}

//April
if(omonth == 4) and (oday == 30)
{
oday = 1;
omonth++;
}

//May
if(omonth == 5) and (oday == 31)
{
oday = 1;
omonth++;
}

//June
if(omonth == 6) and (oday == 30)
{
oday = 1;
omonth++;
}

//July
if(omonth == 7) and (oday == 31)
{
oday = 1;
omonth++;
}

//August
if(omonth == 8) and (oday == 31)
{
oday = 1;
omonth++;
}

//September
if(omonth == 9) and (oday == 30)
{
oday = 1;
omonth++;
}

//October
if(omonth == 10) and (oday == 31)
{
oday = 1;
omonth++;
}

//November
if(omonth == 11) and (oday == 30)
{
oday = 1;
omonth++;
}

//December
if(omonth == 12) and (oday == 31)
{
oday = 1;
omonth++;
}

odate = new Date(oyear,omonth,oday,0,0);
}
if(debug == "y")
{
document.writeln("
Old date : " + oday + "/" + omonth + "/" + oyear + "
");
document.writeln("New date : " + nday + "/" + nmonth + "/" + nyear + "

");
}
document.writeln("The site has been open " + i + " days");

[/code]

Also in the debugging feature in the while loop it doesnt write anything out.

Any help, id be gratefull

Cheers
mark

Comments

  • : Hey..
    : Got ova the time problem and its kno a while loop problem. It doesnt seam to want to keep goin and it only does it once i think. Any ways heres the code:
    :
    : [code]
    :
    : //General
    : var debug = "y";
    : var i = 0;
    : var oweek1 = "-";
    :
    : //Make old vars
    : var odate = new Date(2004,6,20,0,0);
    : var oday = odate.getDate();
    : var omonth = odate.getMonth();
    : var oyear = odate.getYear();
    :
    : //Make new vars
    : var ndate = new Date();
    : var nday = ndate.getDate();
    : var nmonth = ndate.getMonth();
    : nmonth++;
    : var nyear = ndate.getYear();
    :
    : //debug
    : if (debug == "y")
    : {
    : document.writeln("General Vars");
    : document.writeln(debug + "");
    : document.writeln(i + "");
    : document.writeln("Old Dates");
    : document.writeln(oday + "");
    : document.writeln(omonth + "");
    : document.writeln(oyear + "");
    : document.writeln(odate + "");
    : document.writeln("New Dates");
    : document.writeln(nday + "");
    : document.writeln(nmonth + "");
    : document.writeln(nyear + "");
    : }
    :
    : //Find date
    :
    : while(i=0,odate != ndate,i++)
    : {
    : //Debug
    : if(debug =="y")
    : {
    : document.writeln(i + "");
    : document.writeln(oday + "");
    : document.writeln(omonth + "");
    : document.writeln(oyear + "");
    : }
    :
    : oday++;
    :
    : //January
    : if(omonth == 1) and (oday == 31)
    : {
    : oday = 1;
    : omonth++;
    : }
    :
    : //Febuary
    : if(omonth == 2) and (oday == 28)
    : {
    : oday = 1;
    : omonth++;
    : }
    : //March
    : if(omonth == 3) and (oday == 31)
    : {
    : oday = 1;
    : omonth++;
    : }
    :
    : //April
    : if(omonth == 4) and (oday == 30)
    : {
    : oday = 1;
    : omonth++;
    : }
    :
    : //May
    : if(omonth == 5) and (oday == 31)
    : {
    : oday = 1;
    : omonth++;
    : }
    :
    : //June
    : if(omonth == 6) and (oday == 30)
    : {
    : oday = 1;
    : omonth++;
    : }
    :
    : //July
    : if(omonth == 7) and (oday == 31)
    : {
    : oday = 1;
    : omonth++;
    : }
    :
    : //August
    : if(omonth == 8) and (oday == 31)
    : {
    : oday = 1;
    : omonth++;
    : }
    :
    : //September
    : if(omonth == 9) and (oday == 30)
    : {
    : oday = 1;
    : omonth++;
    : }
    :
    : //October
    : if(omonth == 10) and (oday == 31)
    : {
    : oday = 1;
    : omonth++;
    : }
    :
    : //November
    : if(omonth == 11) and (oday == 30)
    : {
    : oday = 1;
    : omonth++;
    : }
    :
    : //December
    : if(omonth == 12) and (oday == 31)
    : {
    : oday = 1;
    : omonth++;
    : }
    :
    : odate = new Date(oyear,omonth,oday,0,0);
    : }
    : if(debug == "y")
    : {
    : document.writeln("Old date : " + oday + "/" + omonth + "/" + oyear + "");
    : document.writeln("New date : " + nday + "/" + nmonth + "/" + nyear + "");
    : }
    : document.writeln("The site has been open " + i + " days");
    :
    : [/code]
    :
    : Also in the debugging feature in the while loop it doesnt write anything out.
    :
    : Any help, id be gratefull
    :
    : Cheers
    : mark
    :
    Here is a script to calculate the difference between 2 dates: http://developer.irt.org/script/2.htm
  • Na its kinda of turned personal because i have tried making this type of thing before and it didnt work at all last time....

    So any suggestions to what is wrong?
  • : Na its kinda of turned personal because i have tried making this type of thing before and it didnt work at all last time....
    :
    : So any suggestions to what is wrong?
    :
    Here's a tutorial on creating loops in JScript: http://www.pageresource.com/jscript/jifelse.htm
  • It's possible there are other problems, but you need to use a for loop instead of while. While loops only take a condition, and check it every iteration. For loops get given a starting value, condition, and command to execute every time. You also need to use semi-colons instead of commas. Change it to
    for (i = 0; odate != ndate; i++) {
    ...
    }
  • : Hey..
    : Got ova the time problem and its kno a while loop problem. It doesnt seam to want to keep goin and it only does it once i think. Any ways heres the code:
    :
    : [code]
    :
    : //General
    : var debug = "y";
    : var i = 0;
    : var oweek1 = "-";
    :
    : //Make old vars
    : var odate = new Date(2004,6,20,0,0);
    : var oday = odate.getDate();
    : var omonth = odate.getMonth();
    : var oyear = odate.getYear();
    :
    : //Make new vars
    : var ndate = new Date();
    : var nday = ndate.getDate();
    : var nmonth = ndate.getMonth();
    : nmonth++;
    : var nyear = ndate.getYear();
    :
    : //debug
    : if (debug == "y")
    : {
    : document.writeln("General Vars");
    : document.writeln(debug + "");
    : document.writeln(i + "");
    : document.writeln("Old Dates");
    : document.writeln(oday + "");
    : document.writeln(omonth + "");
    : document.writeln(oyear + "");
    : document.writeln(odate + "");
    : document.writeln("New Dates");
    : document.writeln(nday + "");
    : document.writeln(nmonth + "");
    : document.writeln(nyear + "");
    : }
    :
    : //Find date
    :
    : while(i=0,odate != ndate,i++)
    : {
    : //Debug
    : if(debug =="y")
    : {
    : document.writeln(i + "");
    : document.writeln(oday + "");
    : document.writeln(omonth + "");
    : document.writeln(oyear + "");
    : }
    :
    : oday++;
    :
    : //January
    : if(omonth == 1) and (oday == 31)
    : {
    : oday = 1;
    : omonth++;
    : }
    :
    : //Febuary
    : if(omonth == 2) and (oday == 28)
    : {
    : oday = 1;
    : omonth++;
    : }
    : //March
    : if(omonth == 3) and (oday == 31)
    : {
    : oday = 1;
    : omonth++;
    : }
    :
    : //April
    : if(omonth == 4) and (oday == 30)
    : {
    : oday = 1;
    : omonth++;
    : }
    :
    : //May
    : if(omonth == 5) and (oday == 31)
    : {
    : oday = 1;
    : omonth++;
    : }
    :
    : //June
    : if(omonth == 6) and (oday == 30)
    : {
    : oday = 1;
    : omonth++;
    : }
    :
    : //July
    : if(omonth == 7) and (oday == 31)
    : {
    : oday = 1;
    : omonth++;
    : }
    :
    : //August
    : if(omonth == 8) and (oday == 31)
    : {
    : oday = 1;
    : omonth++;
    : }
    :
    : //September
    : if(omonth == 9) and (oday == 30)
    : {
    : oday = 1;
    : omonth++;
    : }
    :
    : //October
    : if(omonth == 10) and (oday == 31)
    : {
    : oday = 1;
    : omonth++;
    : }
    :
    : //November
    : if(omonth == 11) and (oday == 30)
    : {
    : oday = 1;
    : omonth++;
    : }
    :
    : //December
    : if(omonth == 12) and (oday == 31)
    : {
    : oday = 1;
    : omonth++;
    : }
    :
    : odate = new Date(oyear,omonth,oday,0,0);
    : }
    : if(debug == "y")
    : {
    : document.writeln("Old date : " + oday + "/" + omonth + "/" + oyear + "");
    : document.writeln("New date : " + nday + "/" + nmonth + "/" + nyear + "");
    : }
    : document.writeln("The site has been open " + i + " days");
    :
    : [/code]
    :
    : Also in the debugging feature in the while loop it doesnt write anything out.
    :
    : Any help, id be gratefull
    :
    : Cheers
    : mark.
    Hi there i think the problem is you wrote the while loop using the for syntax.This is how you write a while statement:
    var count=0;
    while(count<certain value){
    statement;
    count++;
    }do not write it as the for statement which is written as
    for(count=0;count<array_books.length;count++){
    statement;
    }so you used while instead of for.Thats what i think is the problem.
    From bhekisizwe goodluck
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories