Managing Program Flow
We already know that order of the statement is really important in source code. But when you write more code, we as programmer have to know how to control this flow to our benefit. First we have to know the default way how code run. Statement will be executed in order, top to bottom. So, finish one statement, and then finish the next statement until reach end.
It's not good enough for programmer. There are some case that we want our code not running in default way. For example :
- Have different output depends on some variables
- Check if password correct or not
- Handling error
- Repeating some stuff over and over again
The code will still run from top to bottom, but we controlling how the flow go. Maybe you want some statement not to be executed or want same code to be repeated. We have to find a way to group statements, and that's what we will do.