2.2. Variables - JulTob/Ada GitHub Wiki

Variables

Reserved and named space in memory that holds a value of a certain type.

procedure A_Variable is
  I: Integer;
  begin
    I:= 1;
    I:= I+2;
  end A_Variable;

Declaration

In a declaration block

-- Declare a variable using 
-- name : type;
X : Integer; 
-- Initialize a variable using 
-- <name> : <type> := <value>;
Y : Integer := 0;
-- Declare a constant variable using 
-- <name> : constant <type> := <value>;
Z : constant Integer := 0;
-- You can declare/initialize multiple variables of the same type
A, B : Integer := 0;
-- Numeric constant using 
-- <name> : constant := <value>;
-- Numeric constants have infinite precision.
Pi : constant := 3.14159_26535_89793_23846_26433_83279_50288_41971_69399;

Assignment

Número_Alumnos := 35;
Suma_Notas     := 183;
Nombre         := "Pepe";
Media          := Float (Suma_Notas / Número_Alumnos);
Y := Z;

In the body, structure variables can be used in the left side (can be assigned) or the right side (can be read). Constants can only be right side (read).

⚠️ **GitHub.com Fallback** ⚠️