Guide

Step By Step

πŸŒ€ Variables πŸŒ€

Variables are Objects

... But not literal Objects, they are data objects, that hold a value.

We can as many as we want, but they have to belong to a type, so the computer can interpret the data, and save enough memory space for it.

<name> : <type>;
<name> : <type> := value; 
<name> : constant <type> := value;

The variables can change value in the algorithm, but constants can't. Constants must also be initialized when declared (as they wouldn't be able to change value). Variables also can be initialized, but is not mandatory. It's up to you.

Assignation

It is important to notice the difference between assigning := and comparing =

In mathematics the symbol : means it is so defined.

And the equality = means it is equal to as in both sides are compared and is determined true to having the same value.

:= then means is defined as to be equal to. We also read it as becomes.

This is not a quirk in Ada, but a mathematical tradition of five centuries. Following the likes of ALGOL.

Is therefor strange that FORTRAN changed the syntax and meaning of = to mean assignation. Breaking with a tradition from 1550. Other languages blindly followed, confusing mathematicians for decades now. (Not that it isn't easy to process, but asking why such a stupidity is allowed to exist in computer sciences)

:= is therefor a "save the result of the right into the memory variable on the left".

= is a Boolean statement

Statements and expressions

Statements and expressions are parts of code that get evaluated into a value of a type before using them. Expressions usually refer to the specific statements that resolve into booleans.

A + 1
5 > 9
a_number * 3

Algebraic Operations

Algebraic operations can be done in Ada very easily. There exists the traditional operations you may be used to to calculate.

+  Addition
-  Subtraction 
*  Multiplication  
/  Division

Worth to mention that we can't mix types, but we can cast values.

f  := 3.14 * float(2);
f2 := float(7)/float(2);
n  := Integer(2.6); -- returns 3 
n  := 7/2;  --  Returns 3, as the result is integer.
n2 := 7 rem 2; --  Returns 1, the reminder of 7/2 in integers
n3 := 7 mod 2; --  Modulus operator. An example of 

Booleans Operations

These are the Boolean connectors that resolve the expressions to a Boolean value.

  =    equal to, same as
  <    less, before
  >    greater, more, after
  <=   less or equal to, before or same as
  >=   more or equal to, after or same as
  /=   different, not equal, not the same

  and     evaluates two Boolean values and checks both are true
  or      evaluates two Boolean values and checks either is true
  not      evaluates a Boolean value and reverses it