RosettaCodeData/Task/Variables/Ada/variables.ada

20 lines
813 B
Ada
Raw Permalink Normal View History

2016-12-05 22:15:40 +01:00
Name: declare -- a local declaration block has an optional name
A : constant Integer := 42; -- Create a constant
2013-04-11 01:07:29 -07:00
X : String := "Hello"; -- Create and initialize a local variable
2016-12-05 22:15:40 +01:00
Y : Integer; -- Create an uninitialized variable
2013-04-11 01:07:29 -07:00
Z : Integer renames Y: -- Rename Y (creates a view)
2016-12-05 22:15:40 +01:00
function F (X: Integer) return Integer is
-- Inside, all declarations outside are visible when not hidden: X, Y, Z are global with respect to F.
2019-09-12 10:33:56 -07:00
X: Integer := Z; -- hides the outer X which however can be referred to by Name.X
2016-12-05 22:15:40 +01:00
begin
...
end F; -- locally declared variables stop to exist here
2013-04-11 01:07:29 -07:00
begin
Y := 1; -- Assign variable
2016-12-05 22:15:40 +01:00
declare
X: Float := -42.0E-10; -- hides the outer X (can be referred to Name.X like in F)
begin
...
end;
end Name; -- End of the scope