1 / 36

Statements

Statements. Presented by Quentin Ochem. university.adacore.com. Some General Information. Statements can be spread on several lines, and need to be completed by a ; Statements need to be written in a sequence of statement. If Statements / If Expressions. If statements If expressions. Ada.

Download Presentation

Statements

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Statements Presented by Quentin Ochem university.adacore.com

  2. Some General Information • Statements can be spread on several lines, and need to be completed by a ; • Statements need to be written in a sequence of statement

  3. If Statements / If Expressions • If statements • If expressions Ada C++ C++ Ada

  4. Condition Operators • Comparison • Binary Boolean Operators and Short Circuit Forms

  5. A Note on the Binary Boolean Operators • “and”, “or” are not short-circuit, both operands are always evaluated • Short-circuit execution is used for “and then” and “or else”

  6. Case Statement / Case Expression Ada C++

  7. Case Statements Rules • All values covered by the type of the expression should be covered • Values must be unique

  8. Loop Statement • Loop is introduced by the loop / end loop block • Loop can be controlled by a exit condition through a while statement

  9. Exit Statements • At any time, a loop can be broken by an exit statement • In case of nested loops, names can be given to exit an outer loop

  10. For .. Loop • Iteration can be done over a range • The range is always given in ascending order • The iteration always goes to the successor, or predecessor if reverse is specified

  11. For .. Loop Control Variable • The variable declared in the for loop can be explicitly typed • It may be of any discrete type. When no range is specified, the whole type range is taken • The control variable is constant in the loop

  12. For .. Loop Range Evaluation • The loop range is evaluated once, when entering the loop

  13. Declare Blocks • In any sequence of statements, it may be useful to re-open declarative blocks or a sub sequence of expressions (for new variable declaration, exception handlers…) • Can be done through a new declare bock

  14. Null Statements • It is illegal to have an empty sequence of statements but … • … it’s possible to use a statement that does nothing, the null statement

  15. (1/10)

  16. (1/10) Compilation error, = is the equality symbol in Ada

  17. (2/10)

  18. (2/10) Compilation error, := is not an operator, can’t be usedin a condition

  19. (3/10)

  20. (3/10) Compilation error, 0 value is missing

  21. (4/10)

  22. (4/10) Compilation Error, 1 .. Integer'Last and 0 .. Integer'Last overlaps

  23. (5/10)

  24. (5/10) Compilation Error, the value evaluated must be discrete

  25. (6/10)

  26. (6/10) Compilation Error, I is constant in the loop, assignment is forbidden

  27. What is the output of this code? (7/10)

  28. What is the output of this code? (7/10) Nothing, the loop has an empty range, needs “reverse 0 .. 10” to be backwards.

  29. (8/10)

  30. (8/10) Compilation Error, the Ada inequality symbol is “/=“

  31. (9/10)

  32. (9/10) Correct, although the I declaration is redundant

  33. What is the output of this code? (10/10)

  34. What is the output of this code? (10/10) “A” / the range is evaluated before entering the loop

More Related