Java • JavaScript • PHP
Order of Execution in a For Loop
November 3, 2018
The For Loop is not only the most important and widely used loop in all modern computer languages, but perhaps the most cleverly invented. The only thing that’s a little confusing for the novice programmer is that the order of execution (or flow of control) happens in a particular order worth exploring.
Here’s the typical syntax for a few C-based derivative languages:
Java
for(int i=0; i<10; i++){ // Statements }
JavaScript/TypeScript
for(let i=0; i<10; i++){ // Statements }
PHP
for($i = 0; $i<10; $i++){ // Statements }
The steps in order of execution in a FOR LOOP are:
for ( step 1; step 2; step 4){ step 3 }
Here’s my video proving it: