Sintaxe:
CASE seletor OF
alvo1 : comando1;
alvo2 : comando2;
alvo3 : comando3;
END;
Sintaxe:
CASE seletor OF
alvo1 : BEGIN
... instruções ...
END;
alvo2 : comando2;
alvo3 : BEGIN
... instruções ...
END;
ELSE comando4;
END;
Exemplo:
{ Um simples exemplo de como se trabalha com a Estrutura Case }
Uses Crt;
Var X : Integer;
Begin
Readln (X);
Case X Of
1 : Writeln ('Ola Mundo'); { E o valor de X for igual a 1, irá executar essa linha }
2 : Writeln ('GNOIA'); { X = 2, essa linha será executada }
3 : Writeln ('Software Livre'); { X = 3 - essa linha será executada }
End;
End.
Exemplo:
Uses Crt;
Var Y, X : Integer;
Begin
Readln (X, Y);
Case X Of
1 : Begin
Y := 4;
Writeln ('Entrou no Primeiro alvo');
End;
2 : Begin
Y := 3;
Writeln ('Entrou no Segundo alvo');
End;
3 : Writeln ('Entrou no Terceiro alvo');
Else Writeln ('Entrou no Else');
End;
End.