Concepts - Variables, Iteration, Functions Flashcards
What is a variable
Variables are storage areas within our programs. If we need to use data later on, it MUST be stored in a variable. Variables can be changed, so we can replace the data being stored at anytime.
What is a constant
Constants are like variable but CANNOT be changed after being set up. Python does not cater for Constants, so to indicate a Constant we use ALL CAPS. This tells the programmer to not change the value in this variable.
What is Declaration
Declaration or declaring a variable means to create the variable.
What is Assignment
Assignment means to add the data to the variable.
What is Iteration
Iteration is performing loops or repeating sequences of code.
What are the 2 types of iteration
There are 2 types of iteration:
Indefinite Iteration (condition controlled)
This is WHILE … ENDWHILE or REPEAT…UNTIL
Definite Iteration (count controlled)
FOR…ENDFOR
What are 2 properties of a ‘while … endwhile’ loop
2 properties:
Boolean Expression
Test the expression at the start of the loop.
num ← RANDOM NUMBER (1,20) guess ← 0 WHILE guess < > num OUTPUT “Enter a Number” guess ← INPUT ENDWHILE
What are 2 properties of a ‘repeat … until’ loop
Similar to WHILE
2 properties:
Boolean Expression
Test the expression at the END of the loop.
num ← RANDOM NUMBER (1,20) REPEAT OUTPUT “Enter a Number” guess ← INPUT UNTIL (guess == num)
What is a ‘for … end for’ loop used for?
Used when you know how many times you are going to repeat something.
Uses Counting(stepping) Variable which could be integers or value from list.
FOR count ← 1 TO 12
PRINT count
ENDFOR
What is Nested Iteration
Loops within Loops: FOR count ← 1 TO 10 FOR times ← 1 TO 10 PRINT count * times ENDFOR ENDFOR
What is a subroutine?
Subroutines can be functions or procedures. They are blocks of code that can be referenced and used anywhere in the program.
Define Built-in functions
These are functions that are pre-defined for the language you are using. ord() chr() len() are examples in python
Define Parameters
These are the variables that are created to bring data into a function or procedure. AKA arguments.
Found in brackets beside subroutine name and if multiple parameters, they are separated by a comma.
Define Local Variable’s
These are variables that are known only in the subroutine in which they are created or paramatised.
Define Global Variables
Global Variables
These are variables that are known throughout the program by all parts