CIS 119 - Demos I

arrays demo

Source code:

   var a = new Array();
   a[0]=7;
   a[5]="Dave";
   document.writeln('Length of a[] is ' + a.length + '<br />');
   for (i=0; i<a.length; i++) {
      document.writeln('a[' + i + '] = ' + a[i] + '<br />');
   }

Output:

repetition - for/in demo

Source code:

   var b = new Array();
   b[0]=7;
   b[5]="Dave";
   document.writeln('Length of b[] is ' + b.length + '<br />');
   for (i in b) {
      document.writeln('b[' + i + '] = ' + b[i] + '<br />');
   }

Output:

break and continue demo

Source code:

   for (j=1; j<11; j++) {
      if (j==2) continue;
      if (j==5) break;
      document.writeln(j + '<br />');
   }

Output:

labeled break and continue demo

Source code:

   outerloop:
      for (i=0; i<5; i++) {
      innerloop:
         for (j=0; j<5; j++) {
            if (i==3) continue outerloop
            if (j==2) break innerloop;
            document.writeln(i + ', ' + j + '<br />');
         }
      }

Output:

void operator demo

Source code:

   document.writeln(void 7);
   <p><a href="javascript: void window.open();">Open a window using void</a></p>

Output:

Open a window using void

empty statement demo

Source code:

   for(sum=0, i=1; i<=10; sum+=i++);
   document.writeln('The sum of the numbers 1 to 10 is ' + sum + '<br />');

Output: