Lecture 2 - Algorithms to Functions Flashcards
What kind of statement is used for a single condition?
If statement
What statement is used for multiple conditions?
If else statement
What statements are used in nested conditions?
Multiple if else statements
What function is used in Multibranch condition?
Switch( )
What kind of loop is used when iterations are known from outset?
For loop
What kind of loop is used when iterations are unknown at outset?
While loop, repeat loop
What is vectorisation?
Implicit Iteration
e.g.
bob
What is the apply function for?
The apply function can be used to apply the same function for example to some large dataset by iterating down a certain column to calculate the same summary statistic
Vectorised Conditional Statement
Acts upon a vector like data structure conditional tests upon each element
What is a function?
Compartmentalised and reusable blocks of code
What is an argument?
Information entering a function.
Good practice to have names.
Can be defined in any order
How do you set a default for an argument?
Assign a value to the argument when the function is defined.
What is the principle of least privilege?
By encapsulating in a function user does not make changes to objects outwith the function.
What is the DRY principle?
Don’t repeat yourself
What are the two different methods to make arguments available to functions?
- Pass by value
- Pass by reference