ProgramProgram StructureAll procedures and functions must be declared before they can be used, as illustrated by this example: procedure First(x : integer); function Second(r : real) : string; var Execution starts at the begin..end block that is not part of a procedure or function definition. The starting point has been marked with a comment so you can recognize it. The main program calls a function named Second, which has to be defined ahead of the main program block. The function named Second calls a procedure named First. Therefore, the procedure named First has to be defined ahead of the function named Second. You might want to think of this structure as building upward. Write your main program block, and then write the definitions for procedures and functions as needed at the top of the script. Always add new procedures and functions to the top of the script which will naturally define them ahead of the program statements that call them. |