Open Bug 1352742 Opened 3 years ago

Example 2: Breaking to a label

Categories

(Developer Documentation :: Learning Area, defect, P5)

All
Other
defect

Tracking

(Not tracked)

UNCONFIRMED

People

(Reporter: pvent08, Unassigned)

References

()

Details

:: Developer Documentation Request

      Request Type: Correction
     Gecko Version: unspecified
 Technical Contact: 

:: Details

It's more of a question about the algorithm flow of 'Example 2: Breaking to a label'. I feel it's not necessary to declare var z=0 at the very top, because the output for the 1st value of z gives 1 and not 0, as opposed to x whose initial value is churned out as 0. If I comment out var z=0 (at the top) I get the same output as if I didn't, which tells me that when I run the program, only z's assignment in the middle of the two while loops gets looked at, but its declaration is out of reach. In fact if I change z's declaration at the top to, say, var = 8, I get exactly the same output as if it was 0 or commented out altogether. So with:

var x = 0;
//var z = 0;

labelCancelLoops: while (true) {
  console.log('Outer loops: ' + x);
  x += 1;
  var z = 1;

  while (true) {
    console.log('Inner loops: ' + z);
    z += 1;
    if (z === 10 && x === 10) {
      break labelCancelLoops;
    } else if (z === 10) {
      break;
    }
  }
}

It works as well. Please let  me know if I'm missing something.
You need to log in before you can comment on or make changes to this bug.