Complément de cours & TDs          © ~/2A env. / H. Nguyen-Phu

Cr. 13.09.2004                     Dernière Màj: 20.10.2008 17h25

 

  

  DES SCHEMAS ALGORITHMIQUES EQUIVALENTS EN L.A.O.

 

 

                               CHOIX SIMPLES (avec instructions uniques)

 

        (                            |                                  

         Condition   ?               | SI  Condition   ALORS 

            Instr_unique_1           |             Instr_unique_1

                :                | SINON  

            Instr_unique_2           |             Instr_unique_2

        )                            | FSI

 

 

                               CHOIX MULTIPLES

 

avec    CAS ...  FINCAS              | avec des conditionnelles emboîtées

                                     |                                  

choix := CAS                         |

      expr1 : Bloc_1; RUPTURE        | SI choix = expr1 ALORS Bloc_1

              // RUPTURE = ‘break;’  |   SINON   // A ne pas oublier !

      expr2 : Bloc_2; RUPTURE        |   SI choix = expr2 ALORS Bloc_2

                                     |     SINON

       ...                           |        ...            

      exprN : Bloc_N; RUPTURE        |       SI Choix= exprN ALORS Bloc_N

                                     |

      AUTRECAS : NOP (ou Bloc_N1)    |          SINON NOP (ou Bloc_N1)

        // NOP : ‘No Operation’      |       FSI

                                     |     FSI

                                     |   FSI

FINCAS                               | FSI

 

Notation: Bloc_j peut être un bloc d'instructions ou une instruction unique.

          NOP signifie aucune instruction à être exécutée ('No OPeration')

 

Remarques:

1- Ne pas oublier le mot clé 'AUTRECAS' (appelé aussi ' AUTREMENT' ou 'PAR

   DEFAUT' dans la littérature informatique) pour assurer la complétude.

2- La traduction en Java de "CAS ... FINCAS" n'est pas directe sauf si

   'choix' et 'exprn ' sont des types simples tels que ENTIER, CARACTERE ...

   ou des éléments de ‘enum’ (cf. Java 5).

 

 

                          BOUCLE ITERATIVE I

 

Boucle "TANT QUE ... FTQ"            | Boucle "POUR   ...     FPOUR"

(Itération conditionnelle)           | (Itération bornée)

                                     |

           i <-- 1                   |

        TANTQUE (i <= n)  FAIRE      | POUR i DE 1 A n  FAIRE

             -Bloc d'instructions-   |         - Même bloc -

              i <-- i + 1            | FPOUR

        FTQUE                        | 

Remarque: La généralisation est possible avec la convention ci-dessous

 

                                     | [Notation acceptée en TD-ASDJ]

        - Bloc_initialisation -      | POUR    ( - Bloc_initialisation -;

        TANTQUE (NON( Cond_arrêt))   | [TANT QUE] NON(Cond_arrêt) [= VRAI];

          FAIRE  - Trait_progressif- |             - Trait_progressif -

        FTQUE                        |          ) [FPOUR]

 

Exemple (cf. retro_an.htm):

 

       x <-- d/2                     | POUR (  x<--d/2;

        TANT QUE(|(x^2-d)/d| > Epsr) |         |(x^2-d)/d| > Epsr;

             FAIRE  x <-- (x+d/x)/2  |         x <-- (x+d/x)/2 ;

        FTQUE                        |       )

 

 

                          BOUCLE ITERATIVE II

 

Boucle "POUR ... PARMI ...   FPOUR"  | Boucle "POUR   ...     FPOUR"

(Itération bornée)  // cf. Java 5    | (Itération bornée)

        e : E  // E : une collection |

        POUR  e  PARMI  E  FAIRE     | POUR i DE 1 A E.Taille()  FAIRE

             -Bloc d'instructions-   |         - Bloc équivalent -

                                    

        FPOUR                        | FPOUR

 

 

                          BOUCLE ITERATIVE III

 

Boucle "REPETER ... JUSQU'A"         | Boucle "FAIRE ...    TANTQUE"

(Itération conditionnelle en L.A.O.) | (cf. ‘do ... while(NON( Cond_arrêt))’ en Java)

       REPETER                       |          FAIRE

           - Traitement itératif -   |              - Traitement itératif -

       JUSQU'A ( Cond_arrêt)         |          TANT QUE (NON( Cond_arrêt))

 

Exemple: Lecture de donnée avec filtrage entre deux bornes Binf et Bsup

       REPETER                       |          FAIRE

              ECRIRE('Taper a:')     |                 ECRIRE('Taper a:')

              LIRE(a)                |                 LIRE(a)

       JUSQU'A (a>=Binf ET a<=Bsup)  |          TANTQUE (a<Binf OU a> Bsup)

 

Remarque :  Utiliser le théorème de MORGAN pour passer d'un schéma à l'autre...

 

 

                          BOUCLE ITERATIVE IV

 

Boucle "REPETER ... JUSQU'A"         | Boucle "Init.; TANTQUE ...   FTQUE"

(Itération conditionnelle en L.A.O.) |         (EMPLOI A EVITER: PREFERER ‘do ... while()’ !)

                                     |         Cond_arrêt <-- FAUX

       REPETER                       |         TANT QUE (NON(Cond_arrêt ))

           - Traitement itératif -   |              - Traitement itératif -

       JUSQU'A ( Cond_arrêt)         |         FTQUE