Next page | Contents page |

Exercise 7 - Loops and conditions

What, if anything, is wrong with each of the following snippets of code? Will each one run? Is it likely to behave as intended?

  1. 
      var i; for (i = 0; i < 10; i++);
        alert (i);
    
  2. 
      for (var i = 0; i < 10; ) { alert (i); i++ }
    
  3. 
      var i = 10; for ( ; i > 0; i--) alert (i);;
    
  4. 
      var paid;
      /* ... here some code which 
         sets a value for paid ... then: */
      if (paid = true) sendReceipt (customer); 
    
Next page | Contents page |