Controlling the flow of logic is a fundamental part of any program, including a PHP script, but what does the phrase actually mean? Logic flow refers to the decision making process whereby you choose which actions to take under which circumstances. Now let's say that is ordinary English!
Think for the moment of the process of filling a bath tub with water. Here's a (greatly) simplified version of the decision making process involved:
- Put some water in
Check the depth
- Deep enough then quit
- Not deep enough continue
Check the temperature
- Too hot, then add some cold water and go back to "Check the depth"
- Too cold, then add some hot water and go back to "Check the depth"
- Add more water
- Go back to "Check the depth"
This process illustrate the basic elements, or building blocks, of logic flow. It has a start point, with an initialization routine (Put some water in.) It continues with a cyclical routine, or loop, that is processed again and again until a certain condition is met. This loop begins with "Check the depth", which is both the marker for the beginning of the loop, and the test for whether or not the whole process should be concluded. The loop contains another condition test (Check the temperature) and three different process branches that are processed based on whether the temperature was too hot, too cold or just right. Each of these process branches returns to the beginning of the loop and the conclusion of the branch.
These fundamental building blocks are common to most programming languages, and vary mostly by the form of how they are implemented.