Menu di scelta

Una struttura molto comune per i programmi di prova.
Viene visualizzato ciclicamente un menu con opzioni

  • 0. Uscita
  • 1. Opzione 1
  • 2. Opzione 2
  • n. Opzione n

L’utente può scegliere quale operazione eseguire oppure uscire con 0.

Var
   scelta: Integer;
Begin
   Repeat
      Writeln('---TITOLO---');
      Writeln(' 0. Uscita');
      Writeln(' 1. Opzione 1');
      Writeln(' 2. Opzione 2');
      ...
      Readln(scelta);
      Case(scelta) Of
         0: { ... USCITA ... }
         1: { ... OPZIONE 1 ... }
         2: { ... OPZIONE 2 ... }
         ...
      End;
   Until(scelta = 0);
End.

Note

  1. La ripetizione del menu
    Repeat
       ...
    Until(scelta = 0);
  2. L’esecuzione dell’operazione corrispondente alla scelta dell’utente
    Case(scelta) Of
       ...
    End;

Utilizzando ClrScr si riparte ogni volta con lo schermo pulito…

Uses
   Crt;
Var
   scelta: Integer;
Begin
   Repeat
      ClrScr;
      Writeln('--- TITOLO ------------------------');
      Writeln(' 0. Uscita');
      Writeln(' 1. Opzione 1');
      Writeln(' 2. Opzione 2');
      ...
      Readln(scelta);
      ClrScr;
      Writeln('-----------------------------------');
      Case(scelta) Of
         0: { ... USCITA ... }
         1: { ... OPZIONE 1 ... }
         2: { ... OPZIONE 2 ... }
         ...
      End;
      Writeln;
      Writeln('-----------------------------------');
      Writeln('Premi INVIO per continuare');
      Readln;
   Until(scelta = 0);
End.