码迷,mamicode.com
首页 > 其他好文 > 详细

Jumps

时间:2014-10-10 18:49:34      阅读:292      评论:0      收藏:0      [点我收藏+]

标签:blog   io   os   ar   java   for   sp   div   art   

labeled statements:

mainloop: while(token != null) {
    // Code omitted...
    continue mainloop;  // Jump to the next iteration of the named loop
    // More code omitted...
}

break:

the break statement, used alone, cause the innermost enclosing loop or switch statement to exit immediately

for(var i = 0; i < a.length; i++) {
    if (a[i] == target) break;
}

  

break labelname;

continue:

the continue statement is similar to the break statement. Instead of exiting a loop, however, continue restart the loop at the next iteration. 

The continue statement, in both its labeled and unlabeled forms, can be only used within the body of a loop.

for(i = 0; i < data.length; i++) {
    if (!data[i]) continue;  // Can‘t proceed with undefined data
    total += data[i];
}

return:

A return statement may appear only within  the body of function. It is a syntax error for it to appear anywhere else.

throw:

function factorial(x) {
    // If the input argument is invalid, throw an exception!
    if (x < 0) throw new Error("x must not be negative");
    // Otherwise, compute a value and return normally
    for(var f = 1; x > 1; f *= x, x--) /* empty */ ;
    return f;
}

try/catch/finally:

try and finally can be used together without a catch clause.

try {
  // Normally, this code runs from the top of the block to the bottom
  // without problems. But it can sometimes throw an exception,
  // either directly, with a throw statement, or indirectly, by calling
  // a method that throws an exception.
}
catch (e) {
  // The statements in this block are executed if, and only if, the try
  // block throws an exception. These statements can use the local variable
  // e to refer to the Error object or other value that was thrown.
  // This block may handle the exception somehow, may ignore the
  // exception by doing nothing, or may rethrow the exception with throw.
}
finally {
  // This block contains statements that are always executed, regardless of
  // what happens in the try block. They are executed whether the try
  // block terminates:
  //   1) normally, after reaching the bottom of the block
  //   2) because of a break, continue, or return statement
  //   3) with an exception that is handled by a catch clause above
  //   4) with an uncaught exception that is still propagating
}

miscellaneous statements:

with (object)
    statement

this statement add object to the front of the scope chain, executes statement, and then restores the scope chain to its original state.

The common use of the with statement is to make it easier to work with deeply nested object hierarchies,like:

document.forms[0].address.value

If you need to write expressions like this a number of times, you can use the with statements to add the form object to the scope chain:

with(document.forms[0]) {
    // Access form elements directly here. For example:
    name.value = "";
    address.value = "";
    email.value = "";
}

you can avoid the with statement like this:

var f = document.forms[0];
f.name.value = "";
f.address.value = "";
f.email.value = "";

debugger:

use strict:

 

 

  

Jumps

标签:blog   io   os   ar   java   for   sp   div   art   

原文地址:http://www.cnblogs.com/woodynd/p/4015844.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!