Summary
Sometimes, we repeat the same piece of code multiple times. Instead of copying and pasting, we can use functions. We learned that functions allow us to repeat the same code multiple times. Additionally, we saw that functions can have parameters. We saw how these parameters could change the function’s behavior depending on what conditionals you have. Besides that, we also learned that functions could return data by using the return
statement. We use the lower camel case naming method, which is similar to variables for function names. We learned how to give the function a fitting name. Additionally, we learned how to split functions if functions have multiple purposes. The same applies when our function gets more than 25 lines. These are all for readability reasons.
Another great way to reduce duplicate code is by using loops. First, we saw how loops repeat the same code a few times. Then, we learned that there are three different loops. We saw that while
and repeat...