Computer programs can be broken down into smaller sub-programs or subroutines to make the code easier to write, understand and maintain. Sub-programs are independent blocks of code that carry out specific tasks and can be programmed and tested separately from the main program. Functions are sub-programs that return a value, while procedures produce an effect without returning a value. Parameters allow data to be passed from the main program to sub-programs.
2. MODULAR CODE
• Computer programs are much easier to write and understand if they are
broken down into smaller blocks. These blocks are called sub-programs
or subroutines.
• Large programs will have teams of developers working on them. Using
sub-programs makes it easier to develop and maintain code.
3. SUB-PROGRAMS
• Independent block of code within the main program.
• Carries out a specific task e.g.
• calculate_area
• display_total
• move_player
• update_score
• Can be programmed and tested independently of other sub-programs.
4. SUB-PROGRAMS
• Each sub-program begins with a declaration which includes:
• the sub-program name
• a list of formal parameters being passed into the sub-program