2.2 Flashcards
What are the 3 programming constructs?
Sequence, selection, iteration
What is a sequence construct?
All code is executed once, one after the other
What is a selection construct?
A boolean expression is used to determine which block of code to execute next
What are the 2 types of selection constructs?
IF, CASE
What is a iteration construct?
A block of code repeated a set number of times, or until a boolean expression is met
What are the 4 main types of iteration construct?
FOR, WHILE, DO WHILE, REPEAT UNTIL
What is a for loop?
Counter controlled loop, repeats fixed number of times
What is a while loop?
Condition controlled loop, Repeats until condition is FALSE
What is a do while loop ?
Condition controlled loop, Condition checked after execution
What is a repeat until loop?
Same as do while
What is a recursive statement?
A subroutine that includes a call to itself
What is an advantage of iteration?
Memory efficient
What is an advantage of recursion?
Code is shorter and easier to read
What are the disadvantages of recursion?
Lots of memory used, Harder to trace
What is a variable?
An identifier that refers to a particular location in memory
What are the 2 types of variable?
Global, Local
What is a global variable?
Declared at the beginning of a program, Used in all subroutines in the program
What is a local variable?
Declared within a module, Can only used in that module
What happens if a local variable shares the same name as a global variable?
The local variable overrides the global variable
What are the disadvantages of global variables?
Duplicate names, Accidental overwriting, Increases complexity
What does modular mean?
A program broken up into individual modules
What are the benefits of modularity?
Easier to write/test/debug, Reusable, Collaboration
What are the two types of modules?
Functions, Procedures
What is a function?
A block of code with its own identifier that performs a specific task, returns a value
What is a procedure?
A section of a program that performs a specific task, Doesn’t return a value
What is a parameter?
A placeholder representing data required by a function in order for it to run
What are the two ways to pass a parameter?
Value, Reference
What happens in passing by value?
A copy of the data is used by the function, The original data remains unchanged
What happens in passing by reference?
A location in memory is passed, changes to the data in the location remain
What does IDE stand for?
Integrated Development Environment
What is an IDE?
A program used for developing programs
What are the key features of an IDE?
Text editor, Translator, Debugging tools, Code completion, Pretty printing
Why is code completion useful?
Reduces syntax errors
Why is pretty printing useful?
Makes the code easier to read