subprog - Procedures-rules for both functions and...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CGN 3421 note_sub page 1 of 6 9/28/98 Procedures- rules for both functions and subroutines One or more lines of code that perform a calculation or a more complicated task. written just once, referenced by main program Convenient when procedure is required more than once in a program The ONLY linked memory is what is passed through the argument list Procedures appear as either a function of a subroutine Functions - calculate a single value based on a single or multiple line procedure 1) statement function A single line added to the beginning of a program before any executable statement Referenced in the main program just like a variable *********************** main program Program NAME Variable declarations function name ( argument list ) = single line expression in terms of argument list open statements executable statements, one or more of which use the function on the r.h.s. of an = sign end *********************** 2) function subprogram Multiple lines needed to calculate the single value. A separate subprogram is written and added after the main program Referenced in the main program just like a variable Local memory is aside from main program, even if variable names are the same must be declared as a real function or an integer function *********************** main program Program NAME variable declarations open statements executable statements, including uses of function name ( argument list ) as a variable end *********************** function subprogram real (or integer) function function name ( argument list ) declare local function variables, different from main program executable statements in terms of argument list and possibly other local variables set function name equal to final single value result of the function return end ***********************
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CGN 3421 note_sub page 2 of 6 9/28/98 Function Usage example #1- statement function **************************************** main program
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 6

subprog - Procedures-rules for both functions and...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online