-1

I came across this today:

check: for (var i = 0; i < versionList.length; i++) {
  var curVersion = versionList[i];

  // find the critical ranges this version is in (the ranges only it can support)
  var ranges = getCriticalRanges(target.name, curVersion);

  // if this version satisfies all of the ranges, then we can replace with this version
  for (var j = 0; j < ranges.length; j++) {
    if (!semver.match(ranges[j], lookup.version))
      continue check;
  }

  // if the version is not equal to our target, deprecate the old version
  if (lookup.version != curVersion) {
    var oldName = lookup.name + '@' + curVersion;

    if (ranges.length) {
      useExisting = true;
      ui.log('info', (nodeSemver.gt(lookup.version, curVersion) ? 'Upgrading' : 'Downgrading') + ' `' + oldName + '` to `' + lookup.version + '`');
    }
    else {
      // wasn't critical anyway - just remove
      deprecated.push(oldName);
    }

    // remove all traces, but leave the package in the file system for cache value
    delete config.depMap[oldName];
    versionList.splice(i--, 1);
  }
}

I've never seen that in JavaScript before. I found it here: https://github.com/jspm/jspm-cli/blob/0.8.0-beta.2/lib/core.js#L328

What is that?

trusktr
  • 44,284
  • 53
  • 191
  • 263

1 Answers1

4

It's a label for continue to jump to.

Example (from the linked page):

loop1:
for (i = 0; i < 3; i++) {      //The first for statement is labeled "loop1"
   loop2:
   for (j = 0; j < 3; j++) {   //The second for statement is labeled "loop2"
      if (i == 1 && j == 1) {
         continue loop1;
      }
      console.log("i = " + i + ", j = " + j);
   }
}

But mind the warning on that same page:

Avoid using labels

Labels are not very commonly used in JavaScript since they make programs harder to read and understand.

Hans Kesting
  • 38,117
  • 9
  • 79
  • 111