Programming techniques Flashcards
If loop
If the condition is true then one or two statements are execute
if condition is not true then statements under loop are skipped and then control is passed to the next statement
Switch/end switch
can be used to compare multiple expressions
Nested statement
Second statement is only checked if the first statement is true
While/ end while loop
The condition is tested upon entry to the loop
Do/until loop
The statements are executed before the condition is evaluated
for/next loop
This is used to repeat a block of instructions a specified number of times
What is modular programming?
This means breaking down a major task into smaller sub tasks
Advantages of modular programming?
Programs can become easier to program and manage (once broken)
each module can be individually tested so it is easier to find errors
Modules can be re-used several times in a program
Much easier to de-bug and maintain
Define a subroutine
A subroutine is a named block of code which performs a specific task within a program
Define global variables
Global variables are variables used in the main program and these can be used anywhere in the program
Define local variables
Local variables can be used within the subroutine and they only exist during the execution of the subroutine.They can not be accessed outside the subroutine and changing the value will have no effect.
Define a Function
A subroutine with a named identifier called as a part of an expression.Returns multiple value or none Function name(parameter)
Define a Procedure
A subroutine with a named identifier can be called from anywhere in the program.when called code is executed and control passed back to the program where the procedure is called from
Returns a single value
Define Iteration
Code that is executed a given number of times or until a condition is met.Can cause infinite loop if condition is not met
Define Variables
Variables are identifier(names) given to memory locations whose contents will change during the course of the program