C# Equivalent to: For i = 30 To 32

  • Thread starter Thread starter Xucyr
  • Start date Start date
X

Xucyr

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?
 
Xucyr said:
But I believe the C# code is way too big, is there any way to shorten
this?

for (int i = 7; i <= 39; i++) {
// do your thing
}

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
 
U¿ytkownik "Xucyr" napisa³:
int i = 7;

do
{
aryBadCoor.SetValue(i + " 25", v);
v++;
i++;
} while (!(i ==39))

for (int i=7; i<=39; i++)
{
aryBadCoor.SetValue(i + " 25", v);
v++;
}

--
____ _
| _ \(_) ___ ___ _ _ piecu(at)go2.pl gg:1277308
| |_) | |/ _ \/ __| | | | --------------------------------
| __/| | __/ (__| |_| | "jutro to dzi¶ - tyle, ¿e jutro"
|_| |_|\___|\___|\__,_| S³awomir Mro¿ek (1981)
 
I think VB is inclusive so I've used a <=, however, if it is not inclusive (32
isn't actually
processed) then change that to a simple <.

for(i = 30; i <= 32; i++) {
}
 
Xucyr said:
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
 
Xucyr said:
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
 
If you're looking for a fast way to convert VB.NET syntax to C#, you can
check out my book, "The .NET Languages: A Quick Translation Guide". It has
translation tables that show the syntax equivalent for the entire VB.NET and
C# language.

Brian Bischof
--
http://www.amazon.com/exec/obidos/ASIN/1893115488



Peter van der Goes said:
Xucyr said:
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
 
in c# you use

for(int i = 7; i <=39; i++)
{
....
}

hope this helps

Fitim Skenderi


Peter van der Goes said:
Xucyr said:
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
 
Back
Top