Computer programs (also known as software, apps or scripts) are created using programming languages.
A programming language is used to describe exactly what a program does, in the finest of detail. It may include instructions for such things as:
- what happens when users interact with it
- how and where its user interface will be displayed
- how and when it might talk to other software on the network
- where any needed data will come from and where it will go
- the decisions that need to be made and how to react to them
- calculations that need to be made to get some kind of result
Another way to think about this, is that programming code describes a task that you want a computer to perform, or an experience that a computer is to create for users.
This code, will then be translated by other programs into something a computer can understand, which is literally ones and zeros.
What are control structures?
The following quote from Wikipedia may shed some light on this topic.
In computer science, control flow is the order in which individual statements, instructions or function calls of an imperative program are executed or evaluated.
Programs that reach a certain level of complexity behave differently depending on what information they have available to them.
For example, playing the same game twice in sequence can yield vastly different results depending on the player's interactions with the game software.
In order for something like that to happen, decisions must be made by the software.
The flow chart of the simple game illustrates one such scenario. Programming the logic depicted in the flow chart would require loops (the arrow that forms a looping path), conditional statements (the arrows branching apart) and subroutines (boxes that would contain other more detailed logic flows).
This “flow” of decisions and behaviours is known as the control flow of the program.
Therefore, with that in mind, control structures are the elements of a programming language that allow you to direct this flow of control. The most common ones typically break down into the following categories:
- Conditional Statements
- Allow you to choose which blocks of code to execute based on some pre-determined criteria
- Loops and Iteration
- Allow you to repeat the execution of blocks of code based on criteria of your choosing
- Subroutines, Procedures or Functions
- Allow you to execute completely separate blocks of code, then return the original spot in the main program when finished.
Gaining some experience working with these structures and beginning to understand when and how to used them is one of the biggest hurdles faced by novice programmers.
These structures may seem cryptic and confusing at first, but I promise that if you persist, you will have a “eureka” moment at which point they will transform from your enemies into your allies.