什么是破坏声明在Axapta中做什么?

时间:2012-10-23 07:23:56

标签: axapta break x++

我有2个循环,第二个是休息; (见下面的代码)

我的问题是:中断是否会导致第二个循环停止或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;
        }
    }...

1 个答案:

答案 0 :(得分:2)

中断只会突破当前代码块。

创建作业并使用此示例代码;

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,并在breakAll之前将break;设置为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;
        }
    }