Today in class, we learned about:
- Control structures
Normally, code will execute in a sequential manner. This is the simplest version of code, but we can make more complex programs as well. There are three fundamental control structures:
Sequential control, which is a form of execution where the code is run line by line in the order that they appear. There are other types of flows as well, and they can be found here along with diagrams of the structures: https://drive.google.com/file/d/1oc1SGn1B4NFyqTYEM6Bu73IP75UAARXL/view
Decision Control structures are dependent on boolean, or whether something is true or false.
This lets them decide whether to run a piece of code or not. For example, the if statement only runs what's in the brackets if the condition is met, or true.
Loop Control structures loop for a certain amount of times or until a condition is met:
For loops loop for a certain amount of times. A for each loops through each element in a data type such as an array. While loops run until a condition is met. Note that this means if you run the code
while (True) {
//do something
}
it will run forever or until the break; function is called.
Another sequence type is a subroutine. These perform a specific task and are packaged in a unit, referred to as a function or a method. This can be called wherever applicable. When called, the program will wait for it to finish executing before continuing.
In the second part of the class, we put this information to use by trying out some practice problems on https://www.lol-101.com/classrooms/introduction-to-java/2-8-project-analyzing-before-coding.
Homework can be found here: https://docs.google.com/forms/d/e/1FAIpQLSf6WJA5jgIB-Sd8Zh65p2aBp9sjdiVEPbYFMMTHbSSS-iGw3g/viewform?usp=sf_link