Order of Execution in a For Loop
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 is not as you see.
Here’s the typical syntax for a few C-based derivative languages:
Java
for(int i=0; i<10; i++){ }
JavaScript/TypeScript
for(let i=0; i<10; i++){ }
PHP
for($i = 0; $i<10; $i++){ }
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:
—
My online training courses:
- Full-Stack Web Development with Django and Angular 8
- Full-Stack Web Development with Flask
- The DOM in JavaScript, jQuery, AngularJS, and React (Lynda.com).
- The DOM in JavaScript, jQuery, AngularJS, and React (LinkedIn)
- Building JSF Web Applications with Java EE 7 (Lynda.com)
- Building JSF Web Applications with Java EE 7 (LinkedIn)
- Troubleshooting Vue.js (packtpub.com)
- Angular 7 New Features
My book “Developing Business Applications for the Web: With HTML, CSS, JSP, PHP, ASP.NET, and JavaScript” is available on Amazon and MC Press.
Check out my author page at http://amazon.com/author/christianhur