1.break语句
如果在for, while或者do循环中使用的话,是停止最内层的循环。
若break用于switch语句中,用来停止执行后面的case,跳出switch块。
//grammar1
break;
//grammar2
break label;
2.continue语句
用来产生一个新的循环迭代,停止循环中的当前迭代,开始新的迭代,在新的迭代开始前任何条件表达式都会重新评估。
//grammar1
continue;
//grammar2,其中label用来标志重新开始的位置
continue label;
//for example
var i=0;
while(i<10)
{
i++;
if(i=7)
continue;
document.write(i + ".test");
}
3.while语句
只要条件为真,一直执行其后括号中的语句块。
while (condition)
{
//statement_block;
}
while(ThereAreUncalledNamesOnTheList() != false)
{
var name = GetNameFromTheList();
SendEmail(name);
}
4.do … while 语句
当condition为真时,一直执行statement_block这个语句块。
do
{
//statement_block
}while(condition)
//for example
var value=0;
do
{
value++;
Clib.sprintf(value);
}while(value<100);
5.for语句
执行某个语句块固定次数。如果condition返回true,或者没有conditon就执行语句块statement_block。
for([var]counter=start;condition;increment)
{
//statement_block
}
6.for … in 语句
用来循环相关数组(associative array)或者对象的属性。
注意,该语句只能用于相关数组,不能用于其他类型数组,相关数组指用字符串作为所引的数组。
for(LoopVar in object)
{
//statement_block
}
注意:对象至少要有一个属性,否则不能用于该for … in语句。每次循环,变量LoopVar的值是相关数组的元素名称或者对象的属性名称,可以通过array_name[LoopVar] or object[LoopVar]访问值。
function PropBtn_Click() {
var obj = new Object;
var propName;
var msgtext = "";
obj.number = 324567;
obj.string = "Welcome to my world";
obj.date = "April 25,1945";
for (propName in obj)
{
msgtext = msgtext + "The value of obj." + propName + " is " + obj[propName] + ".\n";
}
TheApplication.RaiseErrorText(msgtext);
}
7.goto语句/不建议使用
function clickme_Click() {
restart;
var number = 10;
if (number <= 0)
goto restart;
var factorial = 1;
factorial = (factorial * x);
TheApplication.RaiseErrorText("The factorial of" + number + "is" + factorial + ".");
}
8.if语句
if ( i < 10 )
{
TheApplication().RaiseErrorText("i is less than 10.")
}
else if ( i > 10 )
{
TheApplication().RaiseErrorText("i is greater than 10.");
}
else
{
TheApplication().RaiseErrorText("i is 10.");
}
9.switch语句
switch (key[0])
{
case 'A';
I=I+1;
break;
case 'B';
I=I+2;
break;
case 'C';
I=I+3;
break;
default:
I=I+4;
break;
}
10.throw语句,当发生错误时用来确保代码执行中断。
try
{
//do something
}
catch(e)
{
TheApplication().Trace(e.toString());
throw e;
}
11.try语句
try
{
//statement_block
}
catch
{
//exception_handling_block
[throw exception]
}
finally
{
//statement_block_2
}
12.with语句
with语句为其紧随其后的语句块分配了一个默认对象,所以后面的这个语句块可以不用写对象名称直接使用其属性和方法。
with (object)
{
method1;
method2;
...
methodn;
}
如果你在with块中通过代码跳出了with块,那么with就不会继续起作用了,因为with只对紧随其后的块起作用。
var boBusObj = TheApplication().GetBusObject("Opportunity");
var bcOppty = boBusObj.GetBusComp("Opportunity");
var srowid = bcOppty.GetFieldValue("Id");
try
{
with (bcOppty)
{
SetViewMode(SalesRepView);
ActivateField("Sales Stage");
SetSearchSpec("Id", srowid);
ExecuteQuery(ForwardOnly);
}
}
finally
{
boBusObj = null;
bcOppty = null;
}
var boBusObj = TheApplication().GetBusObject("Opportunity");
var bcOppty = boBusObj.GetBusComp("Opportunity");
var srowid = bcOppty.GetFieldValue("Id");
try
{
with(bcOppty)
{
SetViewMode(SalesRepView);
ActivateField("Sales Stage");
SetSearchSpec("Id",srowid);
ExecuteQuery(ForwardOnly);
}
}
finally
{
boBusObj = null;
bcOppty = null;
}