0 then Ada.Text_IO.Put_Line ("POSITIVE RESULT :" & Integer'Image (C)); else Ada.Text_IO.Put_Line ("NEGATIVE RESULT :" & Integer'Image (C)); end if; end Hello; Main subprogram name (can be any Ada identifier) End of main name (optional)"> 0 then Ada.Text_IO.Put_Line ("POSITIVE RESULT :" & Integer'Image (C)); else Ada.Text_IO.Put_Line ("NEGATIVE RESULT :" & Integer'Image (C)); end if; end Hello; Main subprogram name (can be any Ada identifier) End of main name (optional)">

Presentation is loading. Please wait.

Presentation is loading. Please wait.

Slide: 1 Copyright © AdaCore Your First Ada Program Presented by Quentin Ochem University.adacore.com.

Similar presentations


Presentation on theme: "Slide: 1 Copyright © AdaCore Your First Ada Program Presented by Quentin Ochem University.adacore.com."— Presentation transcript:

1 Slide: 1 Copyright © AdaCore Your First Ada Program Presented by Quentin Ochem University.adacore.com

2 Slide: 2 Copyright © AdaCore with Ada.Text_IO; procedure Hello is A, B, C : Integer; begin A := Integer'Value (Ada.Text_IO.Get_Line); B := Integer'Value (Ada.Text_IO.Get_Line); C := A + B; if C = 0 then Ada.Text_IO.Put_Line ("RESULT IS 0"); elsif C > 0 then Ada.Text_IO.Put_Line ("POSITIVE RESULT :" & Integer'Image (C)); else Ada.Text_IO.Put_Line ("NEGATIVE RESULT :" & Integer'Image (C)); end if; end Hello;

3 Slide: 3 Copyright © AdaCore with Ada.Text_IO; procedure Hello is A, B, C : Integer; begin A := Integer'Value (Ada.Text_IO.Get_Line); B := Integer'Value (Ada.Text_IO.Get_Line); C := A + B; if C = 0 then Ada.Text_IO.Put_Line ("RESULT IS 0"); elsif C > 0 then Ada.Text_IO.Put_Line ("POSITIVE RESULT :" & Integer'Image (C)); else Ada.Text_IO.Put_Line ("NEGATIVE RESULT :" & Integer'Image (C)); end if; end Hello; Main subprogram name (can be any Ada identifier) End of main name (optional)

4 Slide: 4 Copyright © AdaCore with Ada.Text_IO; procedure Hello is A, B, C : Integer; begin A := Integer'Value (Ada.Text_IO.Get_Line); B := Integer'Value (Ada.Text_IO.Get_Line); C := A + B; if C = 0 then Ada.Text_IO.Put_Line ("RESULT IS 0"); elsif C > 0 then Ada.Text_IO.Put_Line ("POSITIVE RESULT :" & Integer'Image (C)); else Ada.Text_IO.Put_Line ("NEGATIVE RESULT :" & Integer'Image (C)); end if; end Hello; Variables declaration, only before begin

5 Slide: 5 Copyright © AdaCore with Ada.Text_IO; procedure Hello is A, B, C : Integer; begin A := Integer'Value (Ada.Text_IO.Get_Line); B := Integer'Value (Ada.Text_IO.Get_Line); C := A + B; if C = 0 then Ada.Text_IO.Put_Line ("RESULT IS 0"); elsif C > 0 then Ada.Text_IO.Put_Line ("POSITIVE RESULT :" & Integer'Image (C)); else Ada.Text_IO.Put_Line ("NEGATIVE RESULT :" & Integer'Image (C)); end if; end Hello; Statements, only between begin … end

6 Slide: 6 Copyright © AdaCore with Ada.Text_IO; procedure Hello is A, B, C : Integer; begin A := Integer'Value (Ada.Text_IO.Get_Line); B := Integer'Value (Ada.Text_IO.Get_Line); C := A + B; if C = 0 then Ada.Text_IO.Put_Line ("RESULT IS 0"); elsif C > 0 then Ada.Text_IO.Put_Line ("POSITIVE RESULT :" & Integer'Image (C)); else Ada.Text_IO.Put_Line ("NEGATIVE RESULT :" & Integer'Image (C)); end if; end Hello; The Ada assignment is := The Ada equality operator is =

7 Slide: 7 Copyright © AdaCore with Ada.Text_IO; procedure Hello is A, B, C : Integer; begin A := Integer'Value (Ada.Text_IO.Get_Line); B := Integer'Value (Ada.Text_IO.Get_Line); C := A + B; if C = 0 then Ada.Text_IO.Put_Line ("RESULT IS 0"); elsif C > 0 then Ada.Text_IO.Put_Line ("POSITIVE RESULT :" & Integer'Image (C)); else Ada.Text_IO.Put_Line ("NEGATIVE RESULT :" & Integer'Image (C)); end if; end Hello; ' introduces a special property, called attribute

8 Slide: 8 Copyright © AdaCore with Ada.Text_IO; procedure Hello is A, B, C : Integer; begin A := Integer'Value (Ada.Text_IO.Get_Line); B := Integer'Value (Ada.Text_IO.Get_Line); C := A + B; if C = 0 then Ada.Text_IO.Put_Line ("RESULT IS 0"); elsif C > 0 then Ada.Text_IO.Put_Line ("POSITIVE RESULT :" & Integer'Image (C)); else Ada.Text_IO.Put_Line ("NEGATIVE RESULT :" & Integer'Image (C)); end if; end Hello; Value is an attribute transforming a String to a value of a type Image is an attribute transforming a value of a type to a String

9 Slide: 9 Copyright © AdaCore with Ada.Text_IO; procedure Hello is A, B, C : Integer; begin A := Integer'Value (Ada.Text_IO.Get_Line); B := Integer'Value (Ada.Text_IO.Get_Line); C := A + B; if C = 0 then Ada.Text_IO.Put_Line ("RESULT IS 0"); elsif C > 0 then Ada.Text_IO.Put_Line ("POSITIVE RESULT :" & Integer'Image (C)); else Ada.Text_IO.Put_Line ("NEGATIVE RESULT :" & Integer'Image (C)); end if; end Hello; with allow to use a library unit, here Ada.Text_IO for textual functions

10 Slide: 10 Copyright © AdaCore with Ada.Text_IO; procedure Hello is A, B, C : Integer; begin A := Integer'Value (Ada.Text_IO.Get_Line); B := Integer'Value (Ada.Text_IO.Get_Line); C := A + B; if C = 0 then Ada.Text_IO.Put_Line ("RESULT IS 0"); elsif C > 0 then Ada.Text_IO.Put_Line ("POSITIVE RESULT :" & Integer'Image (C)); else Ada.Text_IO.Put_Line ("NEGATIVE RESULT :" & Integer'Image (C)); end if; end Hello; Get_Line reads a line on the command line Put_Line prints text on the command line

11 Slide: 11 Copyright © AdaCore with Ada.Text_IO; procedure Hello is A, B, C : Integer; begin A := Integer'Value (Ada.Text_IO.Get_Line); B := Integer'Value (Ada.Text_IO.Get_Line); C := A + B; if C = 0 then Ada.Text_IO.Put_Line ("RESULT IS 0"); elsif C > 0 then Ada.Text_IO.Put_Line ("POSITIVE RESULT :" & Integer'Image (C)); else Ada.Text_IO.Put_Line ("NEGATIVE RESULT :" & Integer'Image (C)); end if; end Hello; & is the concatenation operator, used between String

12 Slide: 12 Copyright © AdaCore with Ada.Text_IO; procedure Hello is A, B, C : Integer; begin A := Integer'Value (Ada.Text_IO.Get_Line); B := Integer'Value (Ada.Text_IO.Get_Line); C := A + B; if C = 0 then Ada.Text_IO.Put_Line ("RESULT IS 0"); elsif C > 0 then Ada.Text_IO.Put_Line ("POSITIVE RESULT :" & Integer'Image (C)); else Ada.Text_IO.Put_Line ("NEGATIVE RESULT :" & Integer'Image (C)); end if; end Hello; elsif introduces an alternative decision if … then delimitates a decision, no need for parenthesis

13 Slide: 13 Copyright © AdaCore Quiz

14 Slide: 14 Copyright © AdaCore Identify the Errors with Ada.Text_IO; procedure Hello is A, B : Integer; A = Integer'Image (Ada.Text_IO.Get_Line); B = Integer'Image (Ada.Text_IO.Get_Line); if A == B then Ada.Text_IO.Put_Line ("A EQUALS B, VALUE IS " & A); end if; end Hello;

15 Slide: 15 Copyright © AdaCore with Ada.Text_IO; procedure Hello is A, B : Integer; A = Integer'Image (Ada.Text_IO.Get_Line); B = Integer'Image (Ada.Text_IO.Get_Line); if A == B then Ada.Text_IO.Put_Line ("A EQUALS B, VALUE IS " & A); end if; end Hello;

16 Slide: 16 Copyright © AdaCore with Ada.Text_IO; procedure Hello is A, B : Integer; A = Integer'Image (Ada.Text_IO.Get_Line); B = Integer'Image (Ada.Text_IO.Get_Line); if A == B then Ada.Text_IO.Put_Line ("A EQUALS B, VALUE IS " & A); end if; end Hello; “begin” is needed to introduce a sequence of statements

17 Slide: 17 Copyright © AdaCore with Ada.Text_IO; procedure Hello is A, B : Integer; begin A = Integer'Image (Ada.Text_IO.Get_Line); B = Integer'Image (Ada.Text_IO.Get_Line); if A == B then Ada.Text_IO.Put_Line ("A EQUALS B, VALUE IS " & A); end if; end Hello; The Ada assignment instruction is :=

18 Slide: 18 Copyright © AdaCore with Ada.Text_IO; procedure Hello is A, B : Integer; begin A := Integer'Image (Ada.Text_IO.Get_Line); B := Integer'Image (Ada.Text_IO.Get_Line); if A == B then Ada.Text_IO.Put_Line ("A EQUALS B, VALUE IS " & A); end if; end Hello; Image converts a number into a string, Value would convert a string to a number

19 Slide: 19 Copyright © AdaCore with Ada.Text_IO; procedure Hello is A, B : Integer; begin A := Integer'Value (Ada.Text_IO.Get_Line); B := Integer'Value (Ada.Text_IO.Get_Line); if A == B then Ada.Text_IO.Put_Line ("A EQUALS B, VALUE IS " & A); end if; end Hello; The Ada equality operator is =

20 Slide: 20 Copyright © AdaCore with Ada.Text_IO; procedure Hello is A, B : Integer; begin A := Integer'Value (Ada.Text_IO.Get_Line); B := Integer'Value (Ada.Text_IO.Get_Line); if A = B then Ada.Text_IO.Put_Line ("A EQUALS B, VALUE IS " & A); end if; end Hello; A is not a String, need to be converted through Integer’Image (A)

21 Slide: 21 Copyright © AdaCore with Ada.Text_IO; procedure Hello is A, B : Integer; begin A := Integer'Value (Ada.Text_IO.Get_Line); B := Integer'Value (Ada.Text_IO.Get_Line); if A = B then Ada.Text_IO.Put_Line ("A EQUALS B, VALUE IS " & Integer'Image (A)); end if; end Hello;

22 Slide: 22 Copyright © AdaCore university.adacore.com


Download ppt "Slide: 1 Copyright © AdaCore Your First Ada Program Presented by Quentin Ochem University.adacore.com."

Similar presentations


Ads by Google