# Création #
type mois : chaîne : ("janvier","février","mars",
"avril","mai","juin",
"juillet","août","septembre",
"octobre","novembre","décembre",);
type num_mois : entier : (1,2,3,4,5,6,7,8,9,10,11,12);# Création # type num_mois : entier : 1..12; type alphabet : caractère : 'A'..'Z'; type été : mois : "juillet".."septembre";
Les constantes# Création # var identificateur : type; var identificateur : type := valeur_initialisatrice; var i : entier; var j : entier := 0; # Affectation # variable := valeur; phrase := "Une chaîne de caractères...";
Les expressions# Création # const IDENTIFICATEUR : type := valeur_constante; const PI : réel := 3.14;
Les opérateurs arithmétiquesvariable : type := expression; nom : chaîne := "Jean-Pierre" + " " + "RODERER"; surface : réel := PI * Rayon ** 2; reussir : booléen := vrai et faux ou vrai et non faux;
Les opérateurs booléensvar resultat : réel := 4 * -5 / -2 + 20 - 5 ** 3 / 10; resultat := ((((4 * (-5)) / (-2)) + 20) - ((5 ** 3) / 10)); resultat := (((-20 / -2) + 20) - (125 / 10)); resultat := 30 - 12.5; resultat := 17.5;
Les opérateurs de comparaisonsnon Exp1 et Exp2 ou Exp3 et non Exp4 ou Exp5 ((((non Exp1) et Exp2) ou (Exp3 et (non Exp4))) ou Exp5)
variable : booléen := expression_comparative; réussite : booléen := i < 10; réussite : booléen := (i < 10) et (j <> 0); L'opérateur de concaténation var resultat : chaîne := chaîne + chaîne2 + caractère + ... + chaîneN; resultat : chaîne := "Bonjour " + 'à' + " tous"; resultat := "Bonjour à tous";
Les opérateurs sont associatifs à gauche hormis l'opérateur de puissance **.
La mise entre paranthèses d'une expression contraint à une évaluation prioritaire de cette dernière.
Les procédures# Création #
proc identificateur[([val param_val: type,...,param_valN: type][;
valres param_val_res: type,...,param_val_resN: type][;
res param_res: type,...,param_résN: type])];
[variable_locale : type := valeur;
...
variable_localeN : type := valeur;]
début
Instructions...
fproc
proc compteur;
var cpt : entier := 0;
i : entier;
début
pour i := 0 jusqu'à 10 faire
cpt := cpt + 1;
écrire(i, " ", cpt);
fpour;
fproc
proc tri(val nb : entier; valres un_tableau :
tableau[1..MAX]; res reussie : boolean)
Les fonctions
# Création #
fonction identificateur([paramètre: type,...,paramètreN: type]): type;
[variable_locale : type := valeur;
...
variable_localeN : type := valeur;]
début
Instructions...
résultat valeur;
ffonction
fonction aire_cercle(diamètre : réel) : réel;
var PI : réel := 3.14;
début
aire : réel := (PI * (diamètre ** 2)) / 2;
resultat aire;
ffonction
# Appel de fonction #
variable : type_fonction :=
identificateur_fonction([argument,..., argumentN]);
surface : réel := aire_cercle(15);
Les structures
# Création #
type identificateur : struct
variable : type,
...,
variableN : type
fstruct;
...
identificateurN struct
variable : type,
...,
variableN : type
fstruct;
type personnel : struct
identifiant : entier,
nom, prénom : chaîne,
date_naissance : chaîne(10),
adresse : chaîne,
code_postal : entier,
ville : chaîne,
pays : chaîne,
telephone : entier
fstruct;
société : struct
num_siret : entier,
nom : chaîne,
dirigeant : personnel,
nb_personnel : entier
fstruct;
# Déclaration de variable structure #
var nom_variable : identificateur_structure;
var dirigeant : personnel;
var entreprise : société;
# Affectation #
identificateur_structure.nom_champs := valeur;
entreprise.dirigeant.nom := "MAGNARD";
entreprise.nom := "ALAPAGE";
entreprise.num_siret := 41426553800010;
# Lecture #
variable : type_champs := identificateur_structure.nom_champs;
pdg : chaîne := entreprise.dirigeant.nom
+ " " + entreprise.dirigeant.prénom
# Utilisation avec avec #
avec identificateur_structure faire
nom_champs := valeur;
variable : type_champs := nom_champs;
favec;
avec entreprise faire
nom := "ALAPAGE";
dirigeant.pays := "France";
avec dirigeant faire
nom := "MAGNARD";
prénom := "Patrice";
favec;
favec;
Les tableaux
# Création #
identificateur : tableau[début..fin{, ..., débutN..finN}] de type
un_tableau : tableau[1..10,1..10] de entier;
#Création d'un tableau bidimensionnel de 100 cellules#
# Affectation #
tableau[index{, indexN}] := valeur;
un_tableau[1,1] := 12;
# Lecture #
tableau[index{, indexN}] := valeur;
type_tableau : variable := un_tableau[1,1] := 12;
Ecriture à l'écran
écrire(valeur);
écrire("Notions d'algorithme");
La structure conditionnelle si...alors...sinon
si expression_booléenne
alors instructions...;
[sinon si seconde_expression_booléenne
alors instructions...;]
[...]
[sinon si Nième_expression_booléenne
alors instructions...;]
[sinon Instructions...;]
fsi
si variable < 10 alors
écrire("La variable est supérieure à 10 :", variable);
sinon si variable > 10 alors
écrire("La variable est inférieure à 10 :", variable););
sinon si variable = 10 alors
écrire("La variable est égale à 10 :", variable););
fsi
La structure conditionnelle choix...cas
choix
expression_booléenne -> cas
Instructions...;
fcas
...
expression_booléenneN -> cas
Instructions...;
fcas
fchoix;
choix
mois = "janvier"
ou mois = "février"
ou mois = "mars" -> cas;
écrire("Nous sommes dans la saison hivernale.");
fcas
mois = "avril"
ou mois = "mai"
ou mois = "juin" -> cas;
écrire("Nous sommes dans la saison du printanière.");
fcas
mois = "juillet"
ou mois = "août"
ou mois = "septembre" -> cas;
écrire("Nous sommes dans la saison estivale.");
fcas
mois = "octobre"
ou mois = "novembre"
ou mois = "décembre" -> cas;
écrire("Nous sommes dans la saison automnale.");
fcas
fchoix;
La structure itérative répéter...jusqu'à
répéter
Instructions...
jusqu'à expression_booléenne
i : entier := 0;
répéter
écrire("Contenu cellule ", i, " : ", tableau[i], "\n");
i := i + 1;
jusqu'à i >= tableau.longueur()
La structure itérative tant que...
tant que expression_booléenne
Instructions...
fin tant que
i : entier := 0;
tant que i < tableau.longueur()
écrire("Contenu cellule ", i, " : ", tableau[i], "\n");
i := i + 1;
fin tant que
La structure itérative pour...
pour expression_d'initialisation
[1(défaut) | pas expression_d'incrémentation]
jusqu'à expression_finale
faire
Instructions...
fin pour
num : entier := 0;
pour i := 0 pas 2 jusqu'à 10 faire
num := num + 1;
écrire("Numéro de boucle et valeur de i : ", num, " et ", i);
fin pour
Lecture des saisies au clavier
lire(variable);
lire(nom);
algorithme
var nom, prénom : chaîne;
début
écrire("Saisissez vos nom et prénom ",
"séparés par une virgule : ");
lire(nom, prénom);
écrire("Bienvenue dans ce programme ",
prénom, " ", nom);
fin