2012-10-23 38 views
1

我有两个while循环,第二个有一个break; (见下面的代码)Axapta会做什么断裂陈述?

我的问题是:将打破停止在第二个循环或2?

while select dirPartyRelationship 
join dirPartyTable 
    where dirPartyTable.RecId == dirPartyRelationship.ChildParty 
join dirPersonName 
    where dirPersonName.Person == dirPartyTable.RecId 
{ 
    while select checkDirRelationship 
     where checkDirRelationship.ChildParty == dirPartyRelationship.RecId 
    { 
     if (checkDirRelationship.RelationshipTypeId == _relationshipType) 
     { 
      break; 
     } 
    }... 

回答

2

break只会突破当前的代码块。

创建一个工作并使用此示例代码;

for(i=0; i<100; i++) 
    { 
     for(j=0; j<100; j++) 
     { 
      info(strfmt("inner loop count %1",j)); 
      break; 
     } 
     info(strfmt("outer loop count %1",i)); 
    } 

你会看到j的从未获得过0,但在打印100次一个简单的例子。

编辑;

如果你想打出来的嵌套循环,你可以解决通过声明boolean,也许叫breakAll,并在内部循环的break;前行设置breakAll为true。在外环检查breakAll这样;

for(i=0; i<100; i++) 
    { 
     for(j=0; j<100; j++) 
     { 
      info(strfmt("inner loop count %1",j)); 
      if (somethingToCheck) 
      { 
       breakAll = true; 
       break; 
      } 
     } 
     info(strfmt("outer loop count %1",i)); 
     if (breakAll) 
     { 
      break; 
     } 
    } 
+0

文档:http://msdn.microsoft.com/en-us/library/aa858014(v=ax.50).aspx –