2.1 Programming Fundamentals Flashcards
Programming Constructs
There are three constructs (ideas of programming) that are used to control the flow of a program:
. Sequence
. Selection
. Iteration
Sequence
Structuring code into a logical, sequential order
Selection
Decision making using if statements
Iteration
Repeating code using for or while loops
Variables
Variables are used to store data in programs. They can be changed as the program runs
What are the two parts of a variable
The data value such as “Emily”
An identifier such as First_Name
How will an efficient program use variables
An efficient program will use variables with sensible identifiers that immediately state their purpose in the program
Variable names
Using variable names like ‘TotalNum’ and ‘Profit’ rather than ‘num1’ and ‘num2’ mean that other programmers will be able to work out the purpose of the code without the need for extensive comments
Large programs
Large programs are often modular - split into subroutines with each subroutine having a dedicated purpose
Local variables
Local variables are declared within a specific subroutine and can only be used within that subroutine
Global variables
Global variables can be used at any point within the whole program
What are the advantages of local variables
. Saves memory
. Easier to debug
. Can reuse subroutines with local variables
What are the advantages of global variables
. Variables can be used anywhere in the whole program (and in multiple subroutines)
. Makes maintenance easier as they are only declared once
. Can be used for constants - values that remain the same
What is a constant
As specified before, a variable is data that can change in value as a program is being run
A constant is data that does not change in value as the program is run - it is fixed and remains the same
What is an example of a constant in math’s
An example of a constant in math’s programs is pi - it will constantly remain at 3.14159 and never change