流程图节点是否允许以任何顺序?

问题描述 投票:0回答:1

我正在编写流程的说明。步骤C,D和E必须在步骤B和步骤F之间完成,但它们可以按任何顺序完成。什么是在流程图中显示的最佳方式?

我希望是一个相关的问题:如果步骤X可以在步骤F和步骤K之间的任何点执行,我将如何在流程图上表示?

flowchart
1个回答
0
投票

我正在编写流程的说明。步骤C,D和E必须在步骤B和步骤F之间完成,但它们可以按任何顺序完成。什么是在流程图中显示的最佳方式?

最好的方法取决于你。有不同的方式,有些更容易编程 - 其他更容易解释。而且,虽然你只询问过程;在编程计算机和指导其他人之间至少存在一些相似之处。

第一个图显示了可以采取的各种路线。这些路由使用类似状态图的方式呈现,而不记录转换的上下文。接下来需要的背景;也就是说,我这样做了 - 下一步是什么..有六种组合,每种都有四条路径,以涵盖所有可能性。

State Machine Diagram

虽然我在下面使用了简单的过程符号;任何人都需要一个预定义的过程符号,如果他们(或可能)用一个单独的流程图图表。

第二个图有两个实现选择。 (使用C伪代码来解释。)

Flowchart

使用for声明,

int next[3]; // next is prepared elsewhere, 
             // because each next[] value is unique there can be no repetition
{
    b();
    for (int i = 0; i < 3; i++)
    {
        case 1: c();
        case 2: d();
        case 3: e();
    }
    f();
}

或者,对于旧时状态机人员,使用goto语句(请注意,goto通常用于美国所得税表格的说明中,在其他情况下可能对指导他人有用。)

int next[4]; // next is prepared elsewhere, next[3] defaults to 4 or F
int i = 0;
{
    b();
    switch (next[i++])
    {
        case 1: goto C;
        case 2: goto D;
        case 3: goto E;
        default: goto F;
    }
C:  c(); // do the C thing
    switch (next[i++])
    {
        case 1: goto C;
        case 2: goto D;
        case 3: goto E;
        default: goto F;
    }
D:  d(); // do the D thing
    switch (next[i++])
    {
        case 1: goto C;
        case 2: goto D;
        case 3: goto E;
        default: goto F;
    }
E:  e(); // do the E thing
    switch (next[i++])
    {
        case 1: goto C;
        case 2: goto D;
        case 3: goto E;
        default: goto F;
    }
F:  f();
}

第三个图使用嵌套的if语句,

Flowchart

int next[3]; // next is prepared elsewhere, next[3] is not used
{
    b();
    if (next[0] == 1)
    { 
        c();
        if (next[1] == 2)
        {
            d();
            e();
        }
        else
        {
            e();
            d();
        }
    }
    else if (next[0]) == 2)
    {
        d();
        if (next[1] == 1)
        {
            c();
            e();
        }
        else
        {
            e();
            c();
        }
    }
    else if (next[0] == 3)
    {
        e();
        if (next[1] == 1)
        {
            c();
            d();
        }
        else
        {
            d();
            c();
        }
    }
    f();
}

第四个图使用switch语句表示所需的模式,

Flowchart

int pattern; // prepared elsewhere, values 1 through 6
{
    b();
    switch (pattern)
    { 
        case 1:
        {
            c();
            d();
            e();
        }
        case 2:
        {
            c();
            e();
            d();
        }
        case 3:
        {
            d();
            c();
            e();
        }
        case 4:
        {
            d();
            e();
            c();
        }
        case 5:
        {
            e();
            c();
            d();
        }
        case 6:
        {
            e();
            d();
            c();
        }
    }
    f();
}

我希望是一个相关的问题:如果步骤X可以在步骤F和步骤K之间的任何点执行,我将如何在流程图上表示?

enter image description here

{
    f();
    if (condition) x();
    g();
    if (condition) x();
    h();
    if (condition) x();
    i();
    if (condition) x();
    j();
    if (condition) x();
    k();
}
© www.soinside.com 2019 - 2024. All rights reserved.