Programming Techniques Flashcards
What is a sequence?
A control structure in which a set of instructions is each executed once, in order in which they are written
What is selection? (Branching)
A control structure in which an option of statements is provided and a condition is used to decide which (if any) statements should be executed
What are some examples of selection?
- If statements = Is a condition true or false? Else statements used if condition is not met, Else If statements used if there are alternate outcomes and End If used to end the statement
- Case statement = uses variable instead of condition to determine which instructions should be executed. Replacement for long if/else statements whose condition depend on same variable. End Select used to end statement
What is iteration?
Control structure in which a group of statements is executed repeatedly (Loops)
What are condition controlled loops?
-Condition that allows us to exit the loop once a particular condition has been met
What is a while loop?
-While loop = condition tested before loop, if condition = false the loop will be ignored. If true the loop will be executed until the condition becomes false. Condition tested on each iteration
What is a Do loop?
- Can be in the form of Do…While, Do..Until, Do while and Do until.
- In Do…While and Do…until the code is executed at least once and the condition is tested at end of loop. Do…While loops as long as condition is met and Do…Until loops until condition is met
- Do While is the same as a while loop
- Do until is the same as a while loop except it will loop until condition is met
What are for loops?
- Count controlled loops that will iterate a specific number of times before exiting
- Use variable to determine how many times the instructions within a loop should execute
- Variable must have start and end value for the loop to be able to function properly.
- With each iteration the variable is Incremented. This continues until the variable reaches the end value and the loop exits
What is variable Scope?
-Range of statements for which it is valid
What is a local variable? +/-?
-Declared in a sub area of the program code, may be in a function or procedure. Values in these variables will only be accessible from the sub program they are declared in. Should be used where ever possible
-Eg; A variable declared within a for loop can only be accessed whilst in that loop. Once the loop has ended the variable can no longer be accessed. (Local variable)
+Only used when sub program is called so main memory usage is limited
-Limited scope
What is a global variable? +/-
-Declared in the root area of the program code (usually the beginning)
-Values stored in these variables will be accessible from any area of the code
+Can be accessed anywhere
-Sit and take up main memory
-Create complications when integrating modules as different modules may have the same global variables but with different values
What are functions?
- Subroutine that executes its statements and returns a single value
- Black boxes, we have them and know what they do but we don’t care how they do it
- Can be reused or called whenever it is needed
- Made up of all the stuff that’s in a subroutine
What are procedures?
- Subroutines that do not return a value
- Act independently of the rest of the program and do not usually return a value to the procedure call
What is a parameter?
- An item of data that is given to a procedure or function
- Written in brackets after the name of the procedure or function
- Can be passed by reference or value
How are parameters passed by value?
- The original data is not changed
- A copy of the original is passed to function/procedure
- Any changes made are lost as soon as the function is no longer in use