Selezioni annidate

if4Le 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

Top…

If A > 0 Then
   Begin
      (* ... da sistemare ... *)
   End
Else
   Begin
      (* ... da sistemare ...*)
   End;

…down

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;

… down

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;

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…

If(A > 0) And (B > 0) Then
   Begin
      Istr11;
      Istr12;
   End
Else If(A > 0) And (B < 0) Then
   Begin
      Istr21;
      Istr22;
   End
...
...