4.1 Fundamentals of Programming Flashcards
The 3 Programming Concepts
- Sequence (do one statement after the other in order)
- Selection (do a set of statements based on a condition)
- Iteration (count or condition controlled)
Nested Statements (definition)
You have one set of commands inside another set of statements
Identifiers (definition)
The unique names given to elements such as variables or routines so that they can be identified
The Importance of Identifiers
It is important that identifiers are meaningful and relevant to the program
so that the program can be understood
Indenting your code (2)
- increases readability
- allows the human eye to trace code block more efficiently
A Pointer (definition)
A data type that stores a value of a given type as well as the memory location of the next item in the list
DIV =
MOD =
DIV = ignore remainder
MOD = remainder
Relational Operations are used in
e.g …
- conditional statements
- =, ==, <, >
Constants vs Variables (definition)
- Variables can change at run time
- Constants are fixed value variables and are fixed in the source code (cannot change during run time)
Advantages of Constants Over Variables (2)
- value cannot be accidentally changed during running of program
- program runs faster as all references to constants are replaced by compiled value at run time, whereas variable’s value has to be retrieved from memory every time
Advantages of Constants Over the Actual Value (2)
- expression much easier to understand with meaningful identifiers
- value only needs to be changed once to change all instances
Strings are
Immutable
Casting (definition)
The process of converting between data types
Concatenation (definition)
Joining together separate strings into a single string
Computers and Random Numbers (3)
- hard for a logical computer to produce something truly random
- no matter how the random numbers are produced the computer must rely on source code produced by a human
- it is impossible for humans not to introduce a portion of bias into a system
Exception Handling (definition) (3)
- The process of anticipating possible errors and writing code to deal with them
- (robust programming)
- can be used to help your program recover from run time errors such as invalid user inputs or divisions by zero
Subroutine (definition) (2)
- A self contained set of commands that can be called from different parts of a program
- Blocks of code which are independent of anything external to them
Types of Subroutines
- Procedures: returns any amount of results including none
- Functions: must return a value/values
Built In Methods:
- abs()
- chr()
- ord()
- upper()
- lower()
- strip()
- len()
- split(‘:’)
- abs(): absolute value
- chr(): ascii character
- ord(): ascii value
- upper(): turn string to uppercase
- lower(): turn string to lowercase
- strip()
- len()
- split(‘:’)