Fundamentals of Programming Flashcards
Pseudocode
Used to write instructions in statements that are somewhere between English and a programming language.
Assignment Statements
= or 🡨
Common Arithmetic Operations
+, -, *, / , **
Output/Input Statements
OUTPUT “”
🡨 USERINPUT
Identifier
A name that points to a memory location.
Assignment
Assigning a value to the memory location to create a variable.
Integer
Whole number.
Decimal/Float
Decimal number.
String
A collection of characters - a word.
Character
A singular letter/symbol.
Boolean
True or False value.
Variable
The value can be changed while the program is running.
Constant
To change the value of a constant, you have to change it in the source code and then recompile. Cannot be the target of assignment. Reduce the risk of errors by reducing access to the memory location.
MOD
Finds the remainder in integer division.
DIV
Returns the integer part of the division.
.len
Returns the length of string.
.find(“”)
Determines if “” occurs in the string.
Relational Operators
> greater than
< less than
=> greater than or equal to
=< less than or equal to
= equal to (== in Python)
<> not equal to (!= in Python)
IF…THEN…ELSE Statements
Control program
flow. Relational operators can be used to compare values within the
expression.
Complex Boolean Expressions
Boolean expressions can include AND, OR and NOT.
ELSE IF
Can be used to evaluate multiple expressions.
CASE
Can be used to evaluate multiple expressions.
Iteration
Repetition. A sequence of instructions is repeated multiple times. This is much more efficient than writing the instructions multiple times. The number of repetitions needed may vary.
WHILE…ENDWHILE Loop
The condition is tested upon entry to the loop. It is possible that the instructions inside the loop might not be executed at all if the entry condition is not met.
Infinite Loops
Infinite loops are often used in 2D games
An “outer” WHILE True… ENDWHILE loop runs the game.
FOR…NEXT Loop
“Definite iteration”. Is used to repeat a block of instructions a specified number of times. The FOR loop uses a counter variable which is automatically incremented each time through the loop. Optionally, a STEP value can be specified to make the counter increase or decrease by any integer.
Nested FOR Loop
These are particularly useful for looping through grids in two-dimensional arrays.
3 Types of Iteration
Indefinite iteration with the condition tested at the start of the loop.
Indefinite iteration with the condition tested at the end of the loop. (Not supported in Python)
Definite iteration where the loop is performed a given number of times.
Data Structures
Built-in structured data types such as arrays and records.
Array
Built-in data structure. Items are referred to by an index using square brackets. The array is a set of elements with the same data type.
2D Array
It is also possible to have two-dimensional arrays, just use two index positions.
Multi-Dimensional Arrays
It is possible to define arrays with any number of dimensions.
Subroutine
A set of instructions with a name. Program execution starts at the first statement in the main program. Program flow will “jump” to the subroutine when called
When the subroutine has finished, the program will continue from where it was called. Procedures and functions are types of subroutine.
Function
A subroutine that returns one or more values. In some programming languages all subroutines are referred to as functions even if no value is returned.
Library Subroutines
Programming languages also come complete with libraries of pre-defined subroutines. The module library has to be imported at the start of the program - like Random in Python.
Parameters
Parameters in parentheses are used to pass data to a subroutine. The order of the parameters in parentheses is important. Parameters appear in subroutine definitions.
Arguements
Arguments appear in subroutine calls. The arguments may vary from call to call, but the parameters are part of the subroutine definition.
Functions returning a Value
A function can return one or more values using a RETURN statement.
Variable Scope
When a variable is in scope the values can be accessed. The scope of a local variable is the subroutine in which it is declared. The variable does not exist outside the subroutine.
Local Variables
A subroutine may have its own variables, these are known as local variables. When you use a name on the left-hand side of an assignment statement in a subroutine, a local variable is automatically created. A local variable can be used only in that subroutine.
Global Variables
A global variable is defined in the main program and can be used in any subroutine called from the main program.
Advantages of Local Variables
The subroutines will be independent of a particular program and can be re-used in different programs. There is no chance of accidentally changing a variable in the main program that is used in a subroutine or vice versa. Keep your subroutines self-contained! Pass as arguments any values that are needed.
Modular Programming
Modular programming means breaking down a major task into smaller subtasks. These subtasks may be further broken down until each ‘module’ performs a single function.
Advantages of Modular Programming
Programs are more easily and quickly written.
Large programs are broken down into subtasks that are easier to program and manage. Each module can be individually tested.
Modules can be re-used several times in a program. Large programs are much easier to debug and maintain.