Programming Techniques Flashcards
Algorithm
A set of step-by-step instructions to solve a problem
Three programming constructs
Sequences, selection, iteration
Sequences
A series of logical steps that perform an action
Selection (branching)
A decision or question that changes the direction of a program depending on the outcome
Examples of sequences
Print statements and variable initialisation
Examples of selections
If and case statements
Iteration
Iteration is the process of repeating sections of a program
Three types of iteration
Infinite loops, count-controlled loops, condition-controlled loops
Infinite loops
Repeats until the user terminates the program or it crashes
Count-controlled loops
Used to make the program repeat the same thing a specific number of times
Example of count-controlled loop
FOR loop
Condition-controlled loops
Repeated based on a certain condition
Example of condition-controlled loop
WHILE loop
DO WHILE loop
Condition-controlled loop - iteration occurs indefinitely as long as specified condition is met
REPEAT UNTIL loop
Condition-controlled loop - iteration occurs indefinitely until specified condition is met