break语句如何工作? [英] How does the break statement work?

查看:81
本文介绍了break语句如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次尝试使用在线参考网站上的一个小的Javascript程序

。我需要对break语句的行为进行一些确认




在以下代码中:


for(row = 0; row< = 7; row ++)A< ----

{

for(col = 0; col< = 7; col ++)B< ----

{

if(check(row,col)==" pass")

break ;

}

}

}


一旦break语句出现,控制权将转移到哪里执行?

它会继续第一个''for''声明(A)还是第二个(B)?


另外我的''检查' '功能需要通过关于它的成功或失败的指示。它通过以下方式实现:


返回(通过);


我这样做是否正确?

欢迎任何有用参考站点的链接。

For the first time, I''m attempting to write a small Javascript program
using one on the online reference sites. I need some confirmation as
to the behaviour of the break statement.

In the following code:

for ( row = 0 ; row <= 7 ; row++ ) A <----
{
for ( col = 0 ; col <=7 ; col++ ) B <----
{
if ( check ( row, col ) == "pass" )
break ;
}
}
}

Where will control pass to once the break statement is executed?
Will it continue with the first ''for'' statement (A) or the second (B)?

Also my ''check'' function needs to pass an indication as to it''s
success or failure. It does it by:

return ( "pass" ) ;

Am I doing it correctly?

Any links to useful reference sites would be welcomed.

推荐答案

3月20日下午4:33,Cogito< nos。 .. @ nospam.nospamwrote:
On Mar 20, 4:33 pm, Cogito <nos...@nospam.nospamwrote:

我第一次尝试用一个小的Javascript程序写一个小的Javascript程序

在线参考网站。我需要对break语句的行为进行一些确认




在以下代码中:
For the first time, I''m attempting to write a small Javascript program
using one on the online reference sites. I need some confirmation as
to the behaviour of the break statement.

In the following code:



请在贴出的代码中使用2个空格缩进。

Please indent using 2 spaces in posted code.


>

for(row = 0; row< = 7 ;行++)A< ----

{

for(col = 0; col< = 7; col ++)B< ----

{

if(check(row,col)==" pass")
>
for ( row = 0 ; row <= 7 ; row++ ) A <----
{
for ( col = 0 ; col <=7 ; col++ ) B <----
{
if ( check ( row, col ) == "pass" )



语法错误:缺失打开{----------------------------- ^


此外,检查未定义,row和col应该保存在本地var。

Syntax error: missing opening { -----------------------------^

Also, check is not defined, row and col should be kept local with var.


break;

}
break ;
}



alert(''Broke to B'');

alert(''Broke to B'');


}
}



alert(''打破A'');

alert(''Broke to A'');


}


执行break语句后控制传递到哪里?
}

Where will control pass to once the break statement is executed?



修复语法错误,然后尝试查看。

Fix the syntax error, then try it and see.


会继续第一个''for''语句(A)或第二个(B)?


此外我的''check''函数需要通知它是''

成功或失败。它通过以下方式实现:


返回(通过);


我这样做了吗?
Will it continue with the first ''for'' statement (A) or the second (B)?

Also my ''check'' function needs to pass an indication as to it''s
success or failure. It does it by:

return ( "pass" ) ;

Am I doing it correctly?



为什么不返回true或false?然后你这样做:


if(check(row,col)){

...

}

Why not just return true or false? Then you do:

if (check(row, col)) {
...
}


欢迎任何有用参考站点的链接。
Any links to useful reference sites would be welcomed.



< URL: http://jibbering.com/faq/index.html >

< URL: http://www.JavascriptToolbox.com/bestpractices/ >

-

Rob

<URL: http://jibbering.com/faq/index.html >
<URL: http://www.JavascriptToolbox.com/bestpractices/ >
--
Rob


2007年3月20日00:16:45 -0700,RobG < rg *** @ iinet.net.auwrote:
On 20 Mar 2007 00:16:45 -0700, "RobG" <rg***@iinet.net.auwrote:

>语法错误:缺少开头
>Syntax error: missing opening



感谢您的回复。

是否有检查语法的工具?我只是用记事本键入

程序。

Thanks for your reply.
Is there a tool to check syntax? I just use notepad to type the
program.


2007年3月20日00:16:45 -0700,RobG < rg *** @ iinet.net.auwrote:
On 20 Mar 2007 00:16:45 -0700, "RobG" <rg***@iinet.net.auwrote:

alert(''Broke to A'');
alert(''Broke to A'');



只是想出了什么警报。这是

调试的好工具!谢谢你的确定。

Just figured out what alert does. This is a great tool for
debugging!!! Thanks for mrntioning it.


>>
我的''检查''功能需要传递关于它的成功或失败的指示。它通过以下方式实现:

返回(通过);

我是否正确地做到了?
>>
Also my ''check'' function needs to pass an indication as to it''s
success or failure. It does it by:

return ( "pass" ) ;

Am I doing it correctly?


为什么不返回true或false?然后你这样做:


if(check(row,col)){

...

}


Why not just return true or false? Then you do:

if (check(row, col)) {
...
}



看起来更优雅。我不知道。

顺便说一句,我如何查看错误情况?

That looks more elegant. I did not know it.
btw, how would I check for a false condition?


这篇关于break语句如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆