Types of Things in Programming
- Variables – Stored data
- Functions – code that does stuff
- Loops – A function that runs when its conditions are met
Variables:
- There are 6 important types of variables:
- Integers – Any whole number
- Floats – Floating point number, any decimal
- Null – No value (NOT THE SAME AS 0)
- Chars – Single characters, can be letters or numbers
- Boolean – True/False
- String – Anything that doesn’t fit into the above categories. ALWAYS has to be enclosed in quote marks
- Variables tend to be created with the following structure:
- For example: int hello = 5
- Create an integer named “hello” that has the value of 5
- If the command value(hello) is called, the interpreter will return 5
- NOTE: VARIABLE NAMES CANNOT CONTAIN SPACES!!!
Functions
- Commands that do things, for example:
- echo/log/print to print text
- add(1,2) will compute 1+2 and return 3
- Functions are specific to programming languages
- Functions can also be created using def(), func() or function()
def hello_world():
print(“Hello world!”)
- Would generate the output:
Hello world!
## Loops
- Loops are functions that execute if their conditions are met
- Types of loops include:
- If loops: IF Condition is met, do XYZ
- While loops: WHILE Condition is met, do XYZ
- For loops: iterates over a sequence
- Example: for every letter in string(“banana”), add 1 to int(number_of_letters)
- Will result in int(number_of_letters) to equal 6
- Loops can be nested inside one another.