Selezioni annidate


Le condizioni perché dei blocchi siano eseguiti a scapito di altri possono essere complicate

image

BasicPascalC
SE(A > 0) ALLORA
    INIZIO
        SE(B > 0) ALLORA
            INIZIO
                istr11
                istr12
                ...
            FINE
         ALTRIMENTI
            INIZIO
                istr21
                istr22
                ...
            FINE
    FINE
ALTRIMENTI
    INIZIO
        istr31
         istr32
         ...
    FINE
If A > 0 Then
    If B > 0 Then
        Istr11
        Istr12
    Else
        Istr21
        Istr22
    End If
Else
    Istr31
    Istr32
End If
If A > 0 Then
    Begin
        If B > 0 Then
            Begin
                Istr11;
                Istr12;
            End
        Else
            Begin
                Istr21;
                Istr22;
            End;
    End
Else
    Begin
        Istr31;
        Istr32;
    End;
if(A > 0)
{
    if(B > 0)
    {
        istr11;
        istr12;
    }
    else
    {   
        istr21;
        istr22;
    }
}
else
{
    istr31;
    istr32;
}

Se l'uso delle istruzioni annidate risulta complesso è consigliabile utilizzare delle selezioni esplicite per ogni singolo blocco di istruzioni a costo di espressioni logiche più complesse...

SE(A > 0 AND B > 0) ALLORA
    INIZIO
        istr11
        istr12
        ...
    FINE
ALTRIMENTI SE(A > 0 AND B <= 0) ALLORA
    INIZIO
        istr21;
        istr22;
        ...
    FINE
ALTRIMENTI SE(A <= 0) ALLORA
    INIZIO
        istr31;
        istr32;
        ...
    FINE


BasicPascalC
If A > 0 Aand B > 0 Then
    Istr11
    Istr12
Else If A > 0 And B <= 0 Then
    Istr21
    Istr22
Else If A <= 0 Then
    Istr31
    Istr32
End If
If A > 0 And B > 0 Then
    Begin
        Istr11;
        Istr12;
    End
Else If A > 0 And B <= 0 Then
    Begin
        Istr21;
        Istr22;
    End
Else If A <= 0 Then
    Begin
        Istr31;
        Istr32;
    End;
if(A > 0 && B > 0)
{
    istr11;
    istr12;
}
else if(A > 0 && B <= 0)
{
    istr21;
    istr22;
}
else if(A <= 0)
{
    istr31;
    istr32;
}
There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki