Article assumes that the reader has a little knowledge of Programming.
Take a look at the languages we use. It’s mostly object-oriented (OO) languages.
Sure, the syntax might be different, but you’ll find 3 common structures:
1. Sequence 2. Selection 3. Iteration
It just means that our programs execute top to bottom, left to right. This is the typical behavior for any program we write.
Let’s look at an example of C ++:
Ok, it might be a stupid program but look at it.
How does this program execute ?
First, it’ll include the iostream
library.
Then, it'll use the std
namespace.
Finally, it'll declare the main()
function which will be called by some other code and then the code inside main()
will execute.
In short, the code executes from top to bottom and left to right.
The branches in our program. These are the if statements.
Let look at another example, this time in JavaScript :
let myItem = 10
let threshold = 3
if(myItem > threshold) {
console.log("My Item is Valuable")
} else {
console.log("My Item is Common")
}
Here, we have branches in our program.
Since myItem
is greater than threshold , the branch that says console.log("My Item is Valuable")
will execute and the one that says console.log("My Item is Common")
will not execute.
The loops in our program.
It’s time for an example again, and this time in Dart :
Here, we have a for
loop that executes in a loop
(Pun Intended).
What the for
loop does is iterate until some kind of a condition is false, in this case when i < items.length
the loop will run and the loop will stop as soon as i >= items.length
.
You’ll see these 3 everywhere (except a few languages like PROLOG). In fact, this has been the case ever since a programming language was introduced.
This means that, if you were to suddenly travel back in time to when programming was first done, then you might faint with the slowness of the computer but eventually you’d be able to write a program fluently.
Also, if we brought someone from back then to our time, then he/she might faint looking at the technological advancement but he/she would be able to program in today’s programming language easily.
So, once you have the grasp of the basics, it’s just the matter of Syntax (which you can Google, by the way) and you’ll be programming in any language as smooth as butter.