for
A for
loop expects three statements separated by
semicolons as arguments. The first statement is executed first, and
only once. It is most frequently used to assign a value to a
variable, which is usually used by the loop to perform iteration. The
second statement is a condition that should return
true
for the loop to continue looping. The third
statement is invoked by the for
loop after every
iteration, and is used to increment or decrement the iteration
variable. For example, the following for
loop
prints all the values of the array myports
:
for(i=0; i < max_index(myports); i++) { display(myports[i],"\n"); }
The function max_index()
returns the number of elements in an
array, and we use it in our
for
loop to ensure that the value of
i
is within range.
Get Network Security Tools now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.