SlideShare une entreprise Scribd logo
1  sur  2
Syntaxe
goto label;
...
...label:statement;
Remarques
1. Une instruction goto ne permet pas d'entrer á l'intérieur d'une instruction composée.
2. une instruction goto ne permet pas de sortir du bloc dans lequel elle se trouve. En
particulier, on ne peut utiliser un goto pour passer d'un sous-programme au programme
appelant.
3. L'instruction goto est á utilisé avec réserve. Il convient de ne pas l'utiliser pour simuler
une instruction répétitive, mais éventuellement lorsque l'écriture du programme s'en
trouve clarifiée, notamment pour quitter une instruction répétitive admettant diverses
conditions de sortie qui peuvent être vérifiées á différents endroits de la boucle.
Exemple
Vérification de l'appartenance d'un entier e á un tableau a : array [1..N] of integer, en
parcourant séquentiellement le tableau.
1° Version sans goto :
trouve := false;
i := 1;
while (i <= n) andnottrouvedo
if a[i] = e thentrouve := true
else i := i + 1;
writeln (trouve);
version avec goto :

2°

trouve := false;
for i := 1 to ndo
if a[i] = e then
begin
trouve := true;
goto 999
end ;
999: writeln (trouve);

1
programexGoto;
label1;
var
a : integer;
begin
a:=10;
(* repeat until loop execution *)
1: repeat
if( a =15)then
begin
(* skip the iteration *)
a:= a +1;
goto1;
end;
writeln('value of a: ', a);
a:= a +1;
until a =20;
end.

L'instruction with fournit une économie d'écriture en permettant á un utilisateur de ne
spécifier qu'une fois le nom de variables de type record (dans l'entête d'instruction) au
lieu de les spécifier chaque fois qu'un champ de la structure est utilisé.
Exemple: Les instructions
UneAuto.annee := 1979 ;
UneAuto.couleur := bleu ;
UneAuto.marque := 'DATSUN CHERRY GL
Peuvent être remplacées par

';

withUneAutodo
begin
annee := 1979 ;
couleur := bleu ;
marque := 'DATSUN CHERRY GL '
end{withUneAuto} ;
Lorsque plusieurs variables sont spécifiées dans l'entête d'instruction, l'instruction
with v1, v2, ..., vndo S ;
estéquivalente á
with v1 dowith v2 do

...

withvndo S ;
2

Contenu connexe

En vedette

Hubungan
HubunganHubungan
Hubunganoldman2
 
Аудитория Интернета Украина Ноябрь 2013 г.
Аудитория Интернета Украина Ноябрь 2013 г.Аудитория Интернета Украина Ноябрь 2013 г.
Аудитория Интернета Украина Ноябрь 2013 г.Roman Kaspirovych
 
Healthy lifestyle2
Healthy lifestyle2Healthy lifestyle2
Healthy lifestyle2Cessy18
 
Avigilon Access Control Manager Certification
Avigilon Access Control Manager CertificationAvigilon Access Control Manager Certification
Avigilon Access Control Manager CertificationMichael Phalin
 
Κορίτσι
ΚορίτσιΚορίτσι
Κορίτσιaskapinaki
 
Honors Final Paper
Honors Final PaperHonors Final Paper
Honors Final PaperHaley Young
 
PwC 2016 Top Issues - The Aging Workforce
PwC 2016 Top Issues - The Aging WorkforcePwC 2016 Top Issues - The Aging Workforce
PwC 2016 Top Issues - The Aging WorkforceTodd DeStefano
 
Aristóteles, Platón y el mimo moderno
Aristóteles, Platón y el mimo modernoAristóteles, Platón y el mimo moderno
Aristóteles, Platón y el mimo modernoColectivo Arista
 

En vedette (12)

Hubungan
HubunganHubungan
Hubungan
 
Seven_Oceans
Seven_OceansSeven_Oceans
Seven_Oceans
 
Аудитория Интернета Украина Ноябрь 2013 г.
Аудитория Интернета Украина Ноябрь 2013 г.Аудитория Интернета Украина Ноябрь 2013 г.
Аудитория Интернета Украина Ноябрь 2013 г.
 
Cardiff by the Sea Library
Cardiff by the Sea LibraryCardiff by the Sea Library
Cardiff by the Sea Library
 
PLN
PLNPLN
PLN
 
Healthy lifestyle2
Healthy lifestyle2Healthy lifestyle2
Healthy lifestyle2
 
Avigilon Access Control Manager Certification
Avigilon Access Control Manager CertificationAvigilon Access Control Manager Certification
Avigilon Access Control Manager Certification
 
Κορίτσι
ΚορίτσιΚορίτσι
Κορίτσι
 
Honors Final Paper
Honors Final PaperHonors Final Paper
Honors Final Paper
 
CFUNDPRESENTATION
CFUNDPRESENTATIONCFUNDPRESENTATION
CFUNDPRESENTATION
 
PwC 2016 Top Issues - The Aging Workforce
PwC 2016 Top Issues - The Aging WorkforcePwC 2016 Top Issues - The Aging Workforce
PwC 2016 Top Issues - The Aging Workforce
 
Aristóteles, Platón y el mimo moderno
Aristóteles, Platón y el mimo modernoAristóteles, Platón y el mimo moderno
Aristóteles, Platón y el mimo moderno
 

Les instructions simples en pascal p2

  • 1. Syntaxe goto label; ... ...label:statement; Remarques 1. Une instruction goto ne permet pas d'entrer á l'intérieur d'une instruction composée. 2. une instruction goto ne permet pas de sortir du bloc dans lequel elle se trouve. En particulier, on ne peut utiliser un goto pour passer d'un sous-programme au programme appelant. 3. L'instruction goto est á utilisé avec réserve. Il convient de ne pas l'utiliser pour simuler une instruction répétitive, mais éventuellement lorsque l'écriture du programme s'en trouve clarifiée, notamment pour quitter une instruction répétitive admettant diverses conditions de sortie qui peuvent être vérifiées á différents endroits de la boucle. Exemple Vérification de l'appartenance d'un entier e á un tableau a : array [1..N] of integer, en parcourant séquentiellement le tableau. 1° Version sans goto : trouve := false; i := 1; while (i <= n) andnottrouvedo if a[i] = e thentrouve := true else i := i + 1; writeln (trouve); version avec goto : 2° trouve := false; for i := 1 to ndo if a[i] = e then begin trouve := true; goto 999 end ; 999: writeln (trouve); 1
  • 2. programexGoto; label1; var a : integer; begin a:=10; (* repeat until loop execution *) 1: repeat if( a =15)then begin (* skip the iteration *) a:= a +1; goto1; end; writeln('value of a: ', a); a:= a +1; until a =20; end. L'instruction with fournit une économie d'écriture en permettant á un utilisateur de ne spécifier qu'une fois le nom de variables de type record (dans l'entête d'instruction) au lieu de les spécifier chaque fois qu'un champ de la structure est utilisé. Exemple: Les instructions UneAuto.annee := 1979 ; UneAuto.couleur := bleu ; UneAuto.marque := 'DATSUN CHERRY GL Peuvent être remplacées par '; withUneAutodo begin annee := 1979 ; couleur := bleu ; marque := 'DATSUN CHERRY GL ' end{withUneAuto} ; Lorsque plusieurs variables sont spécifiées dans l'entête d'instruction, l'instruction with v1, v2, ..., vndo S ; estéquivalente á with v1 dowith v2 do ... withvndo S ; 2