Results 1 to 3 of 3

Thread: Javascript And The While Loop...

  1. #1
    kayoca
    Guest

    Javascript And The While Loop...

    Hello,

    I have a question for all the Java Gurus on this site.
    Something is happening with my While loop. He will only runs once but i want him to run 12 x times. Here is my code.

    objDay is my array. and each of the 12 arrays need to run 31 times.
    Code:
    var MonthCount=0;
    var DayCount =0;
    do {
      while (DayCount <= objDay[MonthCount]) {
        alert ( DayCount );
        DayCount++;
      }
      MonthCount++;
    } while (MonthCount <= objDay.length);
    Can someone tell me what i am doing wrong?? please help..

  2. #2
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    how did you declare you objDay,
    cuz right now it's length is 1,

    declare it as is:

    var objDay=new Array(12);

  3. #3
    kayoca
    Guest
    Thank you for replying. but i have found the solution for it.
    Here is my complete code i designe.
    Code:
    function BerekenWeekNr(Year, Week, Day) {
    
      var Today= new Date("January 1, "+Year)
      var objDay = new Array(11);
      var StartDay = Today.getDay() + 1;
      
      var WeekCount=0;
      var DayCount=1;
      var Weektotal=0;
      var Message='';
      var MonthCount=0;
    
      objDay[0] =31; // January
      if (((Year % 4)==0) && ((Year % 100)!=0) || ((Year % 400)==0)) { 
      objDay[1] =29;  // Februari
      } else { 
      objDay[1] =28;
      }
      objDay[2] =31; // Maart
      objDay[3] =30; // April
      objDay[4] =31; // Mei
      objDay[5] =30; // Juni
      objDay[6] =31; // juli
      objDay[7] =31; // Augustus
      objDay[8] =30; // September
      objDay[9] =31; // Oktober
      objDay[10]=30; // November
      objDay[11]=31; // December
      
      do { DayCount=0;
        while (DayCount <= parseInt(objDay[MonthCount])) {
          for (j=1;j<=7 && DayCount<=objDay[MonthCount];j++) {
            if ( j==7 ) {
              WeekCount++;
            } if ( WeekCount==Week && j==Day ) {
              Message=DayCount+'/'+(MonthCount+1);
            } DayCount++;
          } DayCount++;
        } MonthCount++;
      } while (MonthCount <= objDay.length);
      return(Message);
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width