Algorithmic "imperative" language

Similar documents
Lexical Considerations

1 Lexical Considerations

The PCAT Programming Language Reference Manual

Lexical Considerations

Language Reference Manual simplicity

Advanced Algorithms and Computational Models (module A)

FRAC: Language Reference Manual

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

Full file at

Visual C# Instructor s Manual Table of Contents

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

The SPL Programming Language Reference Manual

Learning Language. Reference Manual. George Liao (gkl2104) Joseanibal Colon Ramos (jc2373) Stephen Robinson (sar2120) Huabiao Xu(hx2104)

CPS122 Lecture: From Python to Java

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

Introduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4.

68000 Assembler by Paul McKee. User's Manual

Ruby: Introduction, Basics

CMPT 125: Lecture 3 Data and Expressions

CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output

Contents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)

ARG! Language Reference Manual

Petros: A Multi-purpose Text File Manipulation Language

Chapter 2 Working with Data Types and Operators

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Department of Computer Science COMP The Programming Competency Test

Review of the C Programming Language for Principles of Operating Systems

CS4120/4121/5120/5121 Spring 2016 Xi Language Specification Cornell University Version of May 11, 2016

The Warhol Language Reference Manual

SOURCE LANGUAGE DESCRIPTION

SMURF Language Reference Manual Serial MUsic Represented as Functions

CPS122 Lecture: From Python to Java last revised January 4, Objectives:

SKILL AREA 306: DEVELOP AND IMPLEMENT COMPUTER PROGRAMS

Ruby: Introduction, Basics

Ruby: Introduction, Basics

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */

3. Java - Language Constructs I

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

The pixelman Language Reference Manual. Anthony Chan, Teresa Choe, Gabriel Kramer-Garcia, Brian Tsau

Chapter 2: Basic Elements of C++

VARIABLES & ASSIGNMENTS

Basics of Java Programming

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

egrapher Language Reference Manual

Review of the C Programming Language

Full file at

In Delphi script, when values are assigned to variables, the colon-equal operator is used; :=

L-System Fractal Generator: Language Reference Manual

Sprite an animation manipulation language Language Reference Manual

9/5/2018. Overview. The C Programming Language. Transitioning to C from Python. Why C? Hello, world! Programming in C

DelphiScript Keywords

do fifty two: Language Reference Manual

Microsoft Visual Basic 2005: Reloaded

The C Programming Language. (with material from Dr. Bin Ren, William & Mary Computer Science)

Onion Language Reference Manual. By: Andrew Aday, (aza2112) Amol Kapoor (ajk2227), Jonathan Zhang (jz2814)

CS112 Lecture: Working with Numbers

Data Types and Variables in C language

Java Primer 1: Types, Classes and Operators

JME Language Reference Manual

Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators

Chapter 3: Operators, Expressions and Type Conversion

1 CS580W-01 Quiz 1 Solution

Programming for Engineers Introduction to C

SPARK-PL: Introduction

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Java+- Language Reference Manual

A Fast Review of C Essentials Part I

X Language Definition

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Microsoft Visual Basic 2015: Reloaded

DaMPL. Language Reference Manual. Henrique Grando

Chapter 2. Lexical Elements & Operators

IPCoreL. Phillip Duane Douglas, Jr. 11/3/2010

Operators. Java operators are classified into three categories:

An Interactive Desk Calculator. Project P2 of. Common Lisp: An Interactive Approach. Stuart C. Shapiro. Department of Computer Science

9/21/17. Outline. Expression Evaluation and Control Flow. Arithmetic Expressions. Operators. Operators. Notation & Placement

CS112 Lecture: Primitive Types, Operators, Strings

CHIL CSS HTML Integrated Language

REVIEW. The C++ Programming Language. CS 151 Review #2

Scheme of work Cambridge International AS & A Level Computing (9691)

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

XPath Expression Syntax

Ordinary Differential Equation Solver Language (ODESL) Reference Manual

CS /534 Compiler Construction University of Massachusetts Lowell. NOTHING: A Language for Practice Implementation

The Compositional C++ Language. Denition. Abstract. This document gives a concise denition of the syntax and semantics

DATABASE AUTOMATION USING VBA (ADVANCED MICROSOFT ACCESS, X405.6)

Decaf Language Reference Manual

IC Language Specification

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

MATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL. John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards

SSOL Language Reference Manual

Computers Programming Course 5. Iulian Năstac

XQ: An XML Query Language Language Reference Manual

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

VENTURE. Section 1. Lexical Elements. 1.1 Identifiers. 1.2 Keywords. 1.3 Literals

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

The Arithmetic Operators

Transcription:

Algorithmic "imperative" language Undergraduate years Epita November 2014 The aim of this document is to introduce breiy the "imperative algorithmic" language used in the courses and tutorials during the undergraduate studies at Epita. Only the syntax is shown here, it is not a coding course. However, you will nd (if you look closely) some valuable tips! Created by Nathalie "Junior" Bouquet Translated by Christophe "Krisboul" Boullay Proofread by Steve "Bobfan" Frank

Contents 1 Algorithm: presentation 3 1.1 General structure of an algorithm............................ 3 1.2 Algorithm Writing Rules................................. 4 1.2.1 Alphabet and lexicon The "words" of the language............. 4 1.2.2 Identier naming conventions.......................... 4 1.2.3 Keywords..................................... 4 1.2.4 Word dividers Special symbols........................ 5 1.2.5 Comments..................................... 5 1.3 Declarations........................................ 5 1.3.1 Constant declarations.............................. 5 1.3.2 Type declarations................................ 5 1.3.3 Variable declarations............................... 6 2 Procedures and Functions (routines) 7 2.1 Routine declaration.................................... 7 Syntax...................................... 7 2.2 Parameters and variables................................ 7 2.2.1 The parameters.................................. 7 Local - Global................................. 7 Parameter declaration............................. 8 2.2.2 (local) declarations................................ 8 2.2.3 Identier Scope.................................. 8 2.3 The procedures...................................... 9 2.4 The functions....................................... 9 Syntax...................................... 9 Return..................................... 9 3 Types 10 3.1 Predened Types..................................... 10 3.2 Types dened by the "coder".............................. 10 3.2.1 Enumerations................................... 10 Declaration................................... 10 Use....................................... 10 3.2.2 Arrays....................................... 10 Declaration................................... 10 Use....................................... 11 3.2.3 Records...................................... 11 Declaration................................... 11 Use....................................... 11 3.2.4 Typed pointers.................................. 11 Declaration................................... 11 Use....................................... 11 1

2 CONTENTS 4 Expressions 12 4.1 Expressions: syntax................................... 12 4.2 Operators......................................... 12 4.2.1 Arithmetic operators............................... 12 4.2.2 Logical operators (and "bitwise")........................ 12 4.2.3 Comparison operators/relational operators.................. 13 4.2.4 String concatenation............................... 13 4.3 Expression evaluation rules............................... 13 4.3.1 Operator precedence............................... 13 4.3.2 Type mismatch.................................. 13 5 Statements 14 5.1 Direct assignment..................................... 14 5.1.1 Syntax....................................... 14 5.1.2 Functioning.................................... 14 5.2 Function and procedure calls.............................. 14 5.2.1 Procedure call: an instruction.......................... 14 5.2.2 Function call: an expression........................... 15 5.3 Conditional statements.................................. 15 5.3.1 if...then...else...end if statements................... 15 Syntax...................................... 15 Functioning................................... 15 5.3.2 Case and switch statements: case of...do...end case.......... 15 Syntax...................................... 15 Functioning................................... 16 5.4 Loop statements..................................... 16 5.4.1 Repetition statements.............................. 16 while...end while.............................. 16 do...while................................... 16 5.4.2 Iteration statement: for...end for...................... 16

Chapter 1 Algorithm: presentation The language presented here is the one used during algorithmic courses and tutorials ("imperative" part) of the two undergraduate years of Epita. There are two "levels" of use: in class, where we will directly use abstract types with their operations, and in tutorials, where the abstract types will be represented using structured types and where the operations will have to be implemented as routines. 1 1.1 General structure of an algorithm Here is the general structure of an algorithm. It is composed of two distinct parts: declarations (before begin) and instructions (between begin and end). algorithm algo_identier begin <constants, types and variables> <instructions> end algorithm algo_identier ˆ <constants, types and variables> : detailed later in this chapter ; ˆ <routines*> : presented in the following chapter ; ˆ <instructions> :presented in chapter 5. *We will hardly ever write full algorithms. To respond to questions, we will rather write "subalgorithms" (called "routines"): functions and procedures. Typographic Note: in all parts of this document the algorithmic elements will be described as follows: keywords identiers <item to be fixed> [optional items]... to indicate that the current structure can be repeated. 1 The next logical step is the implementation machine, which is almost reduced to the translation in the selected language.

4 CHAPTER 1. ALGORITHM: PRESENTATION 1.2 Algorithm Writing Rules 1.2.1 Alphabet and lexicon The "words" of the language As for all languages (and not only in coding, even in Klingon), we must, at rst, dene an alphabet (characters used) and the words which allow us to construct sentences (for example, instructions in this case). Two kinds of words will be present in an Algorithm; Keywords, predened words in the language, and identiers, words created to "name" the variables, the types, the routines... For the latter, there exist very strict rules of construction. 1.2.2 Identier naming conventions An identier is a valid word created to name: a constant, a type, a variable, a routine (function or procedure), a parameter, the main algorithm. The identiers can only contain characters lying within the following ranges: 'a'..'z' 'A'..'Z' '0'..'9' We can also use the character '_' (underscore). To construct an identier, you must respect the following rules: It can't start by a digit. Algorithmic language algorithmique doesn't distinguish between uppercase and lowercase. Obviously, an identier has to be dierent from a keyword, this is to avoid any ambiguity. The use of identiers follows these rules: To be used (in the instruction part), any identier must be declared before (in the declaration part). To nish, to simplify the writing and reading of algorithms, it is strongly recommended to use explicit identiers. 1.2.3 Keywords Keywords will be used to construct the algorithms, the declarations and the instructions. These are predened in the language. As for identiers, no dierence is made between uppercase and lowercase. Keyword 2 list of the algorithmic language: algorithm div global parameters else then record until procedure while otherwise and local for types constants do mod return variables begin end not case decreasing function or if 2 useful!

1.3. DECLARATIONS 5 1.2.4 Word dividers Special symbols The structure of the algorithm, the statements, and the instructions are made so that there is no need of special separators (the dierent parts are simply in sequence). All parts that are started are explicitly nished. We only use the comma "," as word divider for the parameter lists in the routine calls. However, the newline is necessary before starting a new instruction or a new declaration. Some characters and character combinations have special meaning for the algorithmic language. Here's the list: (or <-) (or ^)., : /* */ < > <= >= <> = + - * / ( ) 1.2.5 Comments It is possible to insert comments into the algorithm at any place. Ignored by the compiler, the comments are not part of the algorithm and do not eect its running. So this is just for understanding! Comments are delimited by pairs of symbols /* and */.. We can also use // that allows us to put in comment everything that follows in the same line. 1.3 Declarations Here we will declare all we need for the algorithm: constants, types, variables (as well as procedures and functions that are presented in the following chapter). <declaration part> : <constant declarations> <type declarations> <variable declarations> The order of the declarations is important, and it can not be changed. We will see here the constant, type, and variable declarations. 1.3.1 Constant declarations constants constant_ident = <value>... A constant can not be modied in the algorithm. 1.3.2 Type declarations types type_ident = <type definition>... Here are specied all the types which we will dene later (see section 3.2).

6 CHAPTER 1. ALGORITHM: PRESENTATION 1.3.3 Variable declarations The variables contain the data used by the algorithm. When we declare variables we must assign them a type. The latter must be dened 3. That is to say: either predened in the language or dened by ourselves (see chapter 3). That is why types must be declared before variables. variables type_ident variable_ident 1, variable_ident 2,...... Each line contains a list of variables of the specied type (for clarifying we can dene multiple lists for the same type). Warning: there is no symbol between the type and the identiers! 3 We apply a rule that is very important and valid everywhere: you can not use what is not already known! Therefore, when you want to use something, ensure that it has already been declared, or is predened in the language.

Chapter 2 Procedures and Functions (routines) 2.1 Routine declaration A routine is a sequence of program instructions that perform a specic task and then branch back (return): A "sub-algorithm" we can use it as one step in a larger program and it can be started (called) several time. Syntax algorithm <routine> [<parameters declarations>] [<declarations>] begin <instructions> end algorithm <routine> routine_ident [: type_ident] routine_ident with <routine> = procedure or function. 2.2 Parameters and variables 2.2.1 The parameters Local - Global Any routine can dene parameters not present in the main algorithm. These are input data, provided when calling the routine from another algorithm place. There are two kinds of parameters: The locals and the globals. Local parameter: A local copy of the argument is passed to the routine, which will work on this copy (call by value). Thus, any change performed by the routine will not be passed on to the data passed as a parameter. So that when the call is done, the parameter may receive a local expression (a value) as an eective parameter. Global parameter: There is no copy of the argument, which has to be a variable. The global parameter is link to the variable passed when calling. It must be provided for each global parameter an existing variable name, not an expression, because the routine may change the passed variable (call by reference (by address)).

8 CHAPTER 2. PROCEDURES AND FUNCTIONS (ROUTINES) Parameter declaration The parameter declaration is made like a declaration of variables, with two parts to separate local and global parameters: local parameters type_ident ident_param1, ident_param2,...... parametres globaux type_ident ident_param1, ident_param2,...... The declaration order does not matter, but it can have only one declaration of local parameters and only one of global parameters. 2.2.2 (local) declarations In addition to the parameter declarations, the declarations that follow are the same as for a simple algorithm, except for the routines. So we can declare constants and types, but rarely: constants and types to be shared by all routines are declared in the main algorithm. However, it is frequent to declare variables. These are called local variables belonging to the current routine, unlike the global variables, declared at an higher level (see 2.2.3). It is strongly recommended to use only local variables in the body of the function in which they are declared and not global variables (in fact it is obligatory!). Only "subroutines" may be missing: if the procedure or function has to call another, the latter must have been declared before. 1 2.2.3 Identier Scope The scope of a variable identier or parameter is the part of the algorithm in which the identier is recognized according to its declaration. In other words, all the code lines in which this identier is used will reference the data it denes. An identier will be "visible" in the algorithm where it was declared and in any sub-algorithm called, but never in a higher level. It is possible to have scope conicts, that is to say that a nesting level of routine declares an identier bearing the name of another existing identier of a higher level. Then the rule is the following: the closest version (most deeply nested) of the identier has the priority. There is a rule to add for the construction of identiers: in a declaration block, two identiers can not be identical. However, if they are declared in dierent scopes, two identiers can be identical, but they can then lead to a conict of reach. However, the scope of conict should not pose a problem, insofar as only identiers dened in this routine will be used in the routine! 1 Always the same rule "I am only speaking about what I know", which should be applied more often!

2.3. THE PROCEDURES 9 2.3 The procedures The procedure is a routine that returns nothing. The call for a procedure is an instruction: once the subroutine's task is done, we branch back (return) to the next instruction after the call. 2.4 The functions A function is a processing routine which returns a value. Therefore, the function call is a value (see 5.2.2). Syntax algorithm function function_ident : return_type_ident [parameters local type_ident param_ident......] [parameters global type_ident param_ident......] [variables type_ident...] begin <instructions> param_ident... return <value> end algorithm function function_ident The return type has to be a simple type (integer, character, Boolean, pointer) or a string. Return The value calculated by the function is returned by the instruction return that is followed by an expression. This one must necessarily be included in the function instructions. The return is debranching: its execution terminates the function. So this implies: ˆ Any subsequent instruction after will not be taken into account. ˆ There can be only one executed return. The debranching "power" of return is sometimes used to allow quitting an algorithm before the end 2. That said, this should denitively be avoided unless it is impossible to do otherwise: this is even forbidden to the poor little students of the 1st year undergraduate by the tyrannical teacher in charge of tutorials! 2 We can besides use return without argument in the procedures (there, I've said it!)

Chapter 3 Types 3.1 Predened Types The predened types of the algorithmic language are: integer signed integer numbers 42 real signed foating point numbers 0.154 boolean enumerated type representing values true et false character ANSI character represented by a byte 'a' string character strings "hello" 3.2 Types dened by the "coder" 3.2.1 Enumerations Enumerations are lists of identiers representing legibly a sequence of values linked logically. Declaration types enum_ident = ( value_ident 1, value_ident 2,...) Use Identiers are used as constants and can be directly assigned to variables of the enumerated type. 3.2.2 Arrays Arrays allow us to associate, in a same variable, several data of the same type. Declaration One-dimensional arrays types array_ident = <integer> elts_type_ident The integer can be a value, or a constant integer identier. The element type can be a predened type, or a new type that must have been declared before. Multidimensional arrays In this case, it is sucient to give as many integers as dimensions. types array_ident = <integer 1 > <integer 2 >... elts_type_ident

3.2. TYPES DEFINED BY THE "CODER" 11 Use Access to an array element is done by indicating an index for each dimension. var_ident [<index 1 >, <index 2 >,...] Then we obtain a variable of the element type. Strings can be used as character arrays: s[i] is the character at position i in s for all 1 i length(s). 1 3.2.3 Records A record is a data structure that includes, in a single logical entity, several elements of dierent types. Declaration Use types record_ident = record type_ident 1 eld_ident 11, eld_ident 12,... type_ident 2 eld_ident 21, eld_ident 22,...... end record record_ident To access the contents of a record, the dot notation is used: we give the name of the record (the identier of the variable), followed by a dot (.) and the eld name you want to access. var_ident.eld_ident 3.2.4 Typed pointers A pointer is data which contains the memory address of a variable. The typed pointer points to a variable that has a specic type. Characteristic of this type declaration: it is the only one that can use a previously undeclared type identier. 2 Declaration types pointer_ident = pointed_type_ident Use To access to the pointed variable: var_ident 1 Warning: There is no function length on arrays. 2 This allows us to declare recursive types.

Chapter 4 Expressions An expression is a sequence of calculations that can involve constants, variables, functions, and operators. The expressions are used everywhere in the algorithm: in assignments, as routine parameters, in the control structures, etc. 4.1 Expressions: syntax An expression can be: a value 42 a variable x a constant C a function call cos(x) <expression> BinaryOperator <expression> UnaryOperator <expression> 32 + x not A (<expression>) (a + 15)... 4.2 Operators 4.2.1 Arithmetic operators Classicals: - (unary) + Addition - Subtraction * Multiplication / Division The operands can be of type integer (the result is integer) or real (the result is real), except for the division, with which the result, will always be of type real. See the Implicit type conversion (page 13) for the hybrid cases. integer division: div mod integer division modulo (remainder of the integer division) These operators only work with integer parameters, and the result is an integer. 4.2.2 Logical operators (and "bitwise") Operands are Boolean, so it is a logical operation. The result is a boolean. Boolean expressions are used as conditions in control structures. not logical negation and logical and or logical or 12

4.3. EXPRESSION EVALUATION RULES 13 Reminders: With a and b booleans or booleans expressions: a and b: is only true if a is true and b is true, is false when one of the two is false. a or b: is only false if a is false and b is false, is true when one of the two is true. Important: The operators and and or are sequentials: if the evaluation of the rst operand is sucient to give the result, the second operand will not be evaluated. That is to say: if a is false, a and b will be false, without evaluation of b. 4.2.3 Comparison operators/relational operators Both operands must be of compatible types. The result is always type boolean: true or false. 4.2.4 String concatenation = equal to <> not equal to < less than > greater than <= less than or equal to >= greater than or equal to The operator + may be used with the character strings and the characters for the concatenation. 4.3 Expression evaluation rules 4.3.1 Operator precedence In decreasing order: unary operators - not multiplicative operators * / div mod and additive operators + - or relational operators = < <= > >= <> Expressions in parentheses are evaluated before being used in the next calculations. 4.3.2 Type mismatch A "binary" operator can only works with two values of the same type. There is an exception when one value is a real and the other one is an integer. In this case, the integer value is automatically promoted to a real value. This rule also applies to arithmetic operators (+, -, *, /) and comparison operators.

Chapter 5 Statements 5.1 Direct assignment This instruction allow us to assign a value to a variable. The value can be an expression of any type compatible with the variable type. 5.1.1 Syntax var_ident <expression> avec var_ident: a variable identier ; an array element ; a record eld ; a pointed variable. Note: from there, variable will represent one of these four elements. 5.1.2 Functioning variable <value> A value (an expression) can not be on the left side of an assignment instruction. A variable on the right side of an assignment (and more generally in any expression) must contain a value. 5.2 Function and procedure calls Calling a procedure or function (a routine) is done by its name, possibly followed, by the list of arguments in parentheses. The declaration order of the parameters must be respected. When the call is by reference (global parameter), the argument must be a variable. If it is called by value (local parameter), it can be any expression (see page 7). The distinction between the dierent parameters will be seen in detail in the procedure and function chapter (chap. 2). 5.2.1 Procedure call: an instruction The procedure call is an instruction in itself: procedure_ident (param1, param2,...)

5.3. CONDITIONAL STATEMENTS 15 Examples of procedures: input-output The displaying procedures: write (value 1, value 2,... ) write ("Hello", x) display the character string "Hello", followed by the content of the variable x (provided that x contains a value). The reading procedure: read (variable) read (x) assigns to the x the entered value. 5.2.2 Function call: an expression A function is a routine that returns a value. Therefore, the function call will be usable as any other values (in an expression, as routine parameter, etc.). For instance in an assignment expression: var_ident function_ident (param1, param2,...) A lone function call is not an instruction! 5.3 Conditional statements 5.3.1 if...then...else...end if statements Syntax if <boolean expression> then <instructions> [ else <instructions> ] end if The else <instruction> part is optional. Warning: the endif is obligatory! It will be the same for all structured instructions: this end tag must be present even if there is only one instruction. Functioning if the condition (expressed by the boolean expression) is true then the instruction sequence placed after then will be run. In the opposite case, the instruction sequence placed after else will be run if it exists, otherwise nothing will happen. 5.3.2 Case and switch statements: case of...do...end case Syntax case of <expression> do <expr_liste> : <instructions>... [ otherwise <instructions>] end case

16 CHAPTER 5. STATEMENTS <expr_liste> = a list of values (separated by commas) for the expression. The expression must be of scalar type: integer, character and the enumerations. Functioning The run instructions are those corresponding to the expression value 1. If this value is not in one of the lists, it is the otherwise part (if it exists) that will be run. 5.4 Loop statements 5.4.1 Repetition statements while...end while Syntax while <boolean> <instructions> end while do Functioning The instructions are repeated until the condition is veried. The test is at the beginning of the loop, so the instructions may never be executed. Warning: It is obligatory that the condition becomes false at some point. For that, it requires that the boolean expression contains at least one variable that will be modied in the loop. do...while Syntax do <instructions> while <boolean expression> Functioning The condition is placed at the end. Therefore the instructions will be run at least once, and until the condition becomes false. Of course, the boolean expression constraint stays the same. 5.4.2 Iteration statement: for...end for It allows us to repeat a series of instructions a determined number of times. Syntax for var_ident <begin_expr> to [ downto] <end_expr> do <instructions> end for Functioning The variable must be of scalar type: integer, character and the enumerations. Start and end expressions must be compatible with it. It takes successively all values between the two bounds (in decreasing order if specied). It is impossible to change the planned number of iterations: the loop, variable and the bounds can in no way be changed in the loop! 1 Warning: there is no connection with the Caml pattern matching!