For loop – Using IN

[Total: 0    Average: 0/5]

This file shows how to use a For Loop Using the IN key-word.

Body Code:

<script type=text/javascript>
function showIt() {
  var x = [1,2,3,4,3,2,1];
  var returnVal = "x = ["+x.join()+"]<BR>"
  for (var i in x) {
    returnVal += "x["+i.toString()+"]="+x[i].toString()
    switch(x[i]) {
      case 1:  returnVal+=" == one.<BR>"; break;
      case 2:  returnVal+=" == two.<BR>"; break;
      default: returnVal+=" != one or two.<BR>"; break;
    }
  }
  return returnVal
}
document.write('The results of the above routine running showIt() are as follows:<BR>')
document.writeln(showIt());
</script>

Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *