for loop explained

Post your C# code snippets in here.
1 post Page 1 of 1
Contributors
User avatar
Axel
Coding God
Coding God
Posts: 1928
Joined: Sun Jun 27, 2010 9:15 pm

for loop explained
Axel
how it is in english
Code: Select all
for(data type , variable name = initial amount; variable name <=  amount; variable name + the amount it should be increased with){/*code*/}
I'll give you some examples

i = the character that is used most of the time , you can replace it with anything you want
Code: Select all
for(int i =1; i<=100; i++)
{
Sendspam("da@email");
}
  • int = the data type
    i = the variable name
    1= the initial amount , you can replace this with variables , for example Textbox.Lines.Count
    100= the number where it stops , you can replace this with variables too
    i++ = increase i with 1
what this will do is :
it will execute "Sendspam();" from when 1 becomes 100 while its increased with 1 ( that means 100 times )

I'll make other examples
Code: Select all
for(long x = 0; x <= 9223372036854775806; x++)
{
Messagebox.Show("9,223,372,036,854,775,807 is the absolute maximum of a signed long !")
}
this will execute a Messagebox 9223372036854775807 times (Don't try that folks :D)
If you did notice some mistake tell me !
http://vagex.com/?ref=25000
1 post Page 1 of 1
Return to “Quick Snips”