Structures de contrôle ====================== L'instruction de saut conditionnel ---------------------------------- .. raw:: latex \begin{algorithm} \caption{Exemple de saut conditionnel}\label{saut} \begin{algorithmic}[1] \Procedure{Euclide}{} \Comment{c'est l'algorithme d'Euclide} \State $\textit{stringlen} \gets \text{length of }\textit{string}$ \State $i \gets \textit{patlen}$ \BState \emph{top}: \If {$i > \textit{stringlen}$} \Return false \EndIf \State $j \gets \textit{patlen}$ \BState \emph{loop}: \Comment{C'est le label (l'étiquette)} \If {$\textit{string}(i) = \textit{path}(j)$} \State $j \gets j-1$. \State $i \gets i-1$. \State \textbf{goto} \emph{loop}. \State \textbf{close}; \EndIf \State $i \gets i+\max(\textit{delta}_1(\textit{string}(i)),\textit{delta}_2(j))$. \State \textbf{goto} \emph{top}. \Comment{C'est l'instruction de saut} \EndProcedure \end{algorithmic} \end{algorithm} - **Ligne 7**, le bloc `loop` est aussi un **label** (une étiquette), c'est-à-dire une marque posée qu'il est possible de retrouver dans le programme. - **Ligne 11**, l'instruction `goto` (aller à ) est un saut. D'une manière générale:: Instruction 1 Saut Label1 Instruction 2 ... Label1: Instruction n .. important:: les sauts conditionnels sont à éviter, même s'ils sont implémentés dans le langage cible, car c'est le meilleur moyen d'aboutir à du **code spaghetti**.