Functions and procedures Flashcards
Procedure
A procedure is a piece of code that you can run whenever you want
Function
A function is just like a procedure but one that sends an answer back
Subroutine
A seperate block of code that can be re=used
call
A line of code that runs a subroutine
Parameter
A value that a subroutin expects to be given when called
Why use subroutine?
They are useful to break up large programs into self-contained chunks
Each subroutine can be tested seperatley to make sure it works correctly
Many programmers can work on large program at the sae time, cutting development time
some subroutines can be re-used in other programs
2 key differences between procedures and functions
A function uses parameters to transfer data from the main program into the functiom
A function returns a value into the main program
Subroutines benefits
Make programs easier to read
- They reduce the duplication of code
- complex problems are broken down into smaller chunks