Javascript For Instructions

Javascript For Instructions
Before talking about the instructions, we talked first about the Loop. Loop is the structure of instructions that can be executed repeatedly as long as the required condition not being met. The most common way of doing loop is to add timer / counter variable (variable increases one unit of value during a one-time loop instructions executed (increment)), Loop will stop if the variable counter has passed the certain value which is used as boundary conditions.

Instructions for is one that uses the Loop facility. In the syntax we only need to enter the variable name as the countdown (and also its initial value, and the conditions under which the loop will stop (basically, a condition in which the counter exceeded certain value)), and the last modification instruction counter, increment (increase per unit) or decrement (down per unit)

Complete syntax of this instruction is:

for (counter; the loop_condition_to_stop; counter_modification)
list of instructions or blocks of instruction

For example:
for (i = 1; i <6; i + +) {
Alert (i)

This loop will show the value of i 5 times, from i = 1,2,3,4,5. Loop starts from i = 1 and will always do check and verify whether the value of i is less than 6. Up to i = 6, where the condition is not met then the loop will stop.


Post a Comment