describe flow of data between a procedure and its caller
Named from perspective of called procedure (worker):
From perspective of caller (co-ordinator):
data flow can be shown on structure charts
data flow identifies parameters
down arrow shows a value that is given to the procedure by its caller
----------------------------------------------------- -- print the grade corresponding to a given mark ----------------------------------------------------- procedure print_grade (mark : in INTEGER) is begin -- print_grade case mark is when 85 .. 100 => PUT (" HD"); when 75 .. 84 => PUT (" DN"); when 65 .. 74 => PUT (" CR"); when 50 .. 64 => PUT (" PS"); when 0 .. 49 => PUT (" FL"); when others => null; end case; end print_grade;
up arrow shows a value that is generated by the procedure and returned to its caller
----------------------------------------------------- -- Get a student's exam mark from the user ----------------------------------------------------- procedure get_exam (exam : out INTEGER) is mark : INTEGER; -- number typed by the user begin -- get_exam -- read mark repeatedly until in range loop PUT ("Please enter the exam mark (0-50) "); GET (mark); SKIP_LINE; exit when (0 <= mark) and (mark <= 50); PUT_LINE ("Out of range, please try again"); end loop; exam := mark; -- return the valid mark end get_exam;
two-way arrow shows a value that is supplied by the caller for use in the procedure, and (perhaps) modified within the procedure
----------------------------------------------------- -- Adjust a student's final mark if they bombed the -- exam and need their mark reduced as a result ----------------------------------------------------- procedure adjust (exam : in INTEGER; mark : in out INTEGER) is acceptable : constant := 20; -- min ok exam mark limit : constant := 44; -- max if bad exam begin -- adjust if (exam < acceptable) and (mark > limit) then mark := limit; end if; end adjust;
in | out | in out | |
---|---|---|---|
Can be used to pass information into a procedure | yes | no | yes |
Can be used to pass information back from a procedure | no | yes | yes |
Actual parameter can be a variable name | yes | yes | yes |
Actual parameter can be an expression | yes | no | no |
Can assign to formal parameter inside procedure | no | yes | yes |
Can use value of formal parameter inside procedure | yes | no | yes |