Le condizioni perché dei blocchi siano eseguiti a scapito di altri possono essere complicate…
Procedi in modo top-down utilizzando sempre le etichette di inizio e fine blocco
BASIC |
|
If A > 0 Then ' ... Else ' ... End If |
|
|
If A > 0 Then If B > 0 Then ' ... Else ' ... End If Else If C > 0 Then ' ... Else ' ... End If End If |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
If A > 0 Then If B > 0 Then Istr11 Istr12 Else Istr21 Istr22 End If Else If C > 0 Then Istr31 Istr32 Else Istr41 Istr42 End If End If |
|
C… |
|
if(A > 0) { // ... } else { // ... } |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
if(A > 0) { if(B > 0) { // ... } else { // ... } } else { if(C > 0) { // ... } else { // ... } } |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
if(A > 0) { if(B > 0) { istr11; istr12; } else { istr21; istr22; } } else { if(C > 0) { istr31; istr32; } else { istr41; istr42; } } |
|
Pascal |
|
If A > 0 Then Begin (* ... *) End Else Begin (* ... *) End; |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
If A > 0 Then Begin If B > 0 Then Begin (* ... *) End Else Begin (* ... *) End; End Else Begin If C > 0 Then Begin (* ... *) End Else Begin (* ... *) End; End; |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
If A > 0 Then Begin If B > 0 Then Begin Istr11; Istr12; End Else Begin Istr21; Istr22; End; End Else Begin If C > 0 Then Begin Istr31; Istr32; End Else Begin Istr41; Istr42; End; End; |
|
Python |
|
if(A > 0): pass else: pass |
|
|
if(A > 0): if(B > 0): pass else: pass else: if(C > 0): pass else: pass |
|
|
if(A > 0): if(B > 0): istr11 istr12 else: istr21 istr22 else: if(C > 0): istr31 istr32 else: istr41 istr42 |
|
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…
BASIC |
|
If (A > 0) And (B > 0) Then Istr11 Istr12 ElseIf (A > 0) And (B <= 0) Then Istr21 Istr22 ... ... End If; |
|
C |
|
if(A > 0 && B > 0) { istr11; istr12; } else if(A > 0 && B <= 0) { istr21; istr22; } ... ... |
|
Pascal |
|
If(A > 0) And (B > 0) Then Begin Istr11; Istr12; End Else If(A > 0) And (B <= 0) Then Begin Istr21; Istr22; End ... ... |
|
Python |
|
if(A > 0) and (B > 0): istr11 istr12 elif(A > 0) and (B <= 0): istr21 istr22 ... ... |
|