Statements in Ada

simple_statement ::= null_statement
   | assignment_statement     | exit_statement
   | procedure_call_statement | raise_statement
   | return_statement        
compound_statement ::=
     if_statement
   | case_statement
   | loop_statement
   | block_statement
null_statement ::= null;
statement_identifier ::= direct_name

Assignment

assignment_statement ::=
   variable_name := expression;

Examples


Value  := Max_Value - 1;
Shade  := Blue;
U      := Dot_Product (V, W);
Writer := (Status => Open, Unit => Printer, Line_Count => 60);

Conditional

if_statement ::=
    if condition then
      sequence_of_statements
   {elsif condition then
      sequence_of_statements}
   [else
      sequence_of_statements]
    end if;
condition ::= boolean_expression
case_statement ::=
   case expression is
       case_statement_alternative
      {case_statement_alternative}
   end case;
case_statement_alternative ::=
   when discrete_choice_list =>
      sequence_of_statements

Example programs:

Loop

loop_statement ::=
   [loop_statement_identifier:]
      [iteration_scheme] loop
         sequence_of_statements
       end loop [loop_statement_identifier];
iteration_scheme ::= while condition
   | for loop_parameter_specification
loop_parameter_specification ::=
   defining_identifier in [reverse] discrete_subtype_definition

Example programs:

Block

The block statement changes everything. A simple Ada program consists of two sections: a declaration section and a statement section. This unit of declarations and statements is called a block.
linear structure
Ada program can be more complex than just one block. Statements and declarations themselves may contain blocks. And so an Ada program is actually a tree of nested blocks. This hierachical structure of programs is a key feature of block-structured programming languages.
block structure
block_statement ::=
   [block_identifier:]
       [declare
            declarative_part]
        begin
            handled_sequence_of_statements
        end [block_identifier];

Example


Swap: declare
   Temp : Integer;
begin
   Temp := V; V := U; U := Temp;
end Swap;

Ryan Stansifer <ryan@cs.fit.edu>
Last modified: Thu Oct 1 18:02:24 EDT 1998