2012-10-23 46 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 –