In this section... 5.1.1 Loop Names 5.1.2 Block Names 5.1.3 Exit Statements 5.1.4 Naming End Statements |
Summary of Guidelines from this section |
Process_Each_Page: loop Process_All_The_Lines_On_This_Page: loop ... exit Process_All_The_Lines_On_This_Page when Line_Number = Max_Lines_On_Page; ... Look_For_Sentinel_Value: loop ... exit Look_For_Sentinel_Value when Current_Symbol = Sentinel; ... end loop Look_For_Sentinel_Value; ... end loop Process_All_The_Lines_On_This_Page; ... exit Process_Each_Page when Page_Number = Maximum_Pages; ... end loop Process_Each_Page; |
Regularly naming loops helps you follow Guideline 5.1.3.
It can be difficult to think up a name for every loop, therefore the guideline specifies nested loops. The benefits in readability and second thought outweigh the inconvenience of naming the loops.
Language Ref Manual references: 5.5 Loop Statements
Trip: declare ... begin -- Trip Arrive_At_Airport: declare ... begin -- Arrive_At_Airport Rent_Car; Claim_Baggage; Reserve_Hotel; ... end Arrive_At_Airport; Visit_Customer: declare ... begin -- Visit_Customer -- again a set of activities... ... end Visit_Customer; Departure_Preparation: declare ... begin -- Departure_Preparation Return_Car; Check_Baggage; Wait_For_Flight; ... end Departure_Preparation; Board_Return_Flight; end Trip; |
This guideline is also useful if nested blocks are broken over a screen or page boundary.
It can be difficult to think up a name for each block, therefore the guideline specifies nested blocks. The benefits in readability and second thought outweigh the inconvenience of naming the blocks.
Language Ref Manual references: 5.6 Block Statements
Language Ref Manual references: 5.7 Exit Statements
------------------------------------------------------------------------ package Autopilot is function Is_Engaged return Boolean; procedure Engage; procedure Disengage; end Autopilot; ------------------------------------------------------------------------ package body Autopilot is ... --------------------------------------------------------------------- task Course_Monitor is entry Reset (Engage : in Boolean); end Course_Monitor; --------------------------------------------------------------------- function Is_Engaged return Boolean is ... end Is_Engaged; --------------------------------------------------------------------- procedure Engage is ... end Engage; --------------------------------------------------------------------- procedure Disengage is ... end Disengage; --------------------------------------------------------------------- task body Course_Monitor is ... accept Reset (Engage : in Boolean) do ... end Reset; ... end Course_Monitor; --------------------------------------------------------------------- end Autopilot; ------------------------------------------------------------------------ |
Language Ref Manual references: 6.3 Subprogram Bodies, 7.2 Package Specifications and Declarations, 7.3 Package Bodies, 9.1 Abort Statements, 9.5 Entries, Entry Calls, and Accept Statements