“检查:”在for循环前面是什么意思?

时间:2014-10-08 07:17:00

标签: javascript

我今天遇到了这个:

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);
  }
}

我之前从未在JavaScript中看到过这种情况。我在这里找到了它:https://github.com/jspm/jspm-cli/blob/0.8.0-beta.2/lib/core.js#L328

那是什么?

1 个答案:

答案 0 :(得分:4)

continue的{​​{3}}可以跳转到。{/ p>

示例(来自链接页面):

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);
   }
}

但请注意同一页面上的警告:

  

避免使用标签

     

标签在JavaScript中并不常用   程序更难阅读和理解。