469,607 Members | 2,075 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,607 developers. It's quick & easy.

C# Equivalent to: For i = 30 To 32

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?
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 15 '05 #1
8 1277
Xucyr wrote:
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)
Nov 15 '05 #2
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)

Nov 15 '05 #3
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++) {
}
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

"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?
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Nov 15 '05 #4

"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]
Nov 15 '05 #5
Holy cow you guys are good =)

Thank you!
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 15 '05 #6

"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?
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

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]

Nov 15 '05 #7

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" <p_**********@toadstool.u> wrote in message
news:Oi**************@tk2msftngp13.phx.gbl...

"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?
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com 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]

Nov 15 '05 #8
in c# you use

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

hope this helps

Fitim Skenderi
"Peter van der Goes" <p_**********@toadstool.u> wrote in message
news:Oi**************@tk2msftngp13.phx.gbl...

"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?
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com 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]

Nov 15 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by John | last post: by
2 posts views Thread by Michael Foord | last post: by
6 posts views Thread by Frank Rachel | last post: by
7 posts views Thread by Tim Conner | last post: by
10 posts views Thread by karch | last post: by
9 posts views Thread by Alan Silver | last post: by
14 posts views Thread by grid | last post: by
reply views Thread by guiromero | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.