"Xucyr" <ni***@email-dot-com.no-spam.invalid> wrote in message
news:40**********@Usenet.com...
I can't find any "short" code to make this work without taking 100s of
lines (because I have to keep repeating this process several times).
But this is what I have so far:
int i = 7;
do
{
aryBadCoor.SetValue(i + " 25", v);
v++;
i++;
} while (!(i ==39))
The VB.NET one is:
[code:1:c640d32a4b]
For i = 7 To 39
.SetValue(i & " 8", v)
v += 1
Next i[/code:1:c640d32a4b]
But I believe the C# code is way too big, is there any way to shorten
this?
The C# equivalent is:
for(int i = 7; i <39; i++)
{
// Put your C# equivalent code for what you
// are trying to do here
}
This is counter-controlled repetition in C#.
The three expressions in the () following the for are:
1. The initializer - declares and initializes the loop control variable
2. The continuation test - as long as i is < 39, the loop continues. When i
is no longer < 39, the loop terminates.
3. The modifier - changes the value of the loop control variable at the end
of each pass through the loop. In my example, add 1 to i each time.
To understand the for loop, you need to know what happens when:
1. Execute the initializer (*only* the first time)
2. Execute the test. If the expression is true, execute the controlled code
block.
3. modify the loop control variable according to the modifier expression.
4. Go back to 2. above
5. If 2. results in false, exit to the code following the controlled block
--
Peter [MVP Academic]