(adsbygoogle = window.adsbygoogle || []).push({});
The for loop/ statement counts from one number to another number. You start a for loop with the for keyword which is followed by brackets. The first section inside the brackets is where you set the starting value of the loop counter variable. The second section is the loop end condition. The third is where the loop counter is incremented. The code to run for the loop goes after the brackets.
the explanation of the for statement
[COLOR="#0000CD"]for ([/COLOR] for-initializeropt [COLOR="#0000CD"];[/COLOR] for-conditionopt [COLOR="#0000CD"];[/COLOR] for-iteratoropt [COLOR="#0000CD"])[/COLOR]
a basic for loop looks something like this.
[COLOR="#0000CD"]for (int[/COLOR] i [COLOR="#0000CD"]=[/COLOR] 0; i [COLOR="#0000CD"]<=[/COLOR] 10; i[COLOR="#0000CD"]++[/COLOR] [COLOR="#0000CD"])[/COLOR]
this basically means, this.
you declare the int '
i' as a statement, this means you are inputting the value of '
i', as you can see we have set the value of that with the
'i = 0' so that declares the '
i' represents the value
0.
for the next statement
i [COLOR="#0000CD"]<=[/COLOR] 10[COLOR="#0000CD"];[/COLOR]
this statement means the when '
i' is lower or equal to '
10' the statement will stop looping, which takes you to the next statement.
i[COLOR="#0000CD"]++;[/COLOR]
this part means, if the statement before is false.. other words '
i' Is Not higher or equal to '
10' it will add '
1' value to '
i'
so, for every loop take place if '
i' is smaller than '
10' it will add '1' until it reaches '
10'
so, here's the for loop put together to make a function.
[COLOR="#0000CD"]for (int[/COLOR] i [COLOR="#0000CD"]=[/COLOR] 0[COLOR="#0000CD"];[/COLOR] i [COLOR="#0000CD"]<=[/COLOR] 10[COLOR="#0000CD"];[/COLOR] i[COLOR="#0000CD"]++)[/COLOR]
[COLOR="#0000CD"]{[/COLOR]
console.Write(i);
[COLOR="#0000CD"]}[/COLOR]
this will then make a console application write separate lines, from '
1' to '
10', when it reaches '
10' it will stop looping until that specific function is called again.
you can change the
'i<=10' to something else, use different symbols to make it loop if it's lower or if it's higher.
you can also set the value of 'int i' to anything you want, this is just the starting point of '
i'
but, if you wanted to make a continuous loop which does not stop you simple add no functions in the for statement.
like this
[COLOR="#0000CD"]for([/COLOR];;[COLOR="#0000CD"])[/COLOR]
{
[COLOR="#00cc00"]//Function Here[/COLOR]
}
this will not end until it is returned or ended.