views:

1231

answers:

3

Is it possible to write an infinite for loop in VB.NET?

If so, what is the syntax?

+5  A: 
For i as Integer = 0 To 1 Step 0

If that's not hacky enough, can also write:

For i As Integer = 0 To 2
  i -= 1
Next
Jekke
Yeah, first one is a whole lot cleaner if you for some reason had to use a For loop.
Max Schmeling
the integer would eventually overflow in the second version.
dotjoe
@Joe, it shouldn't. It should cycle back and forth between 0 and 1.
Jekke
i see. i forgot about the hidden "step 1"
dotjoe
+4  A: 
Do
    Something
Loop
erikkallen
he said for loop ;)
jmein
-100. I said for loop.
Why do you care? If it was intended to be a puzzle, you should have stated that in the question.
erikkallen
It's not intended to be a puzzle. Thanks for your input.
If it's not intended to be a puzzle, then this is a valid answer.
Beska
+2  A: 

or

while (true)

end while

ok, proper For answer:

Dim InfiniteLoop as Boolean = true;
For i = 1 to 45687894

    If i = 45687893 And InfiniteLoop = true Then i = 1
End For
ck
he said for loop ;)
jmein
Maybe that's because he didn't know about other kinds of loops. A for loop that doesn't for will just confuse people because there's no point.
ck
No more point than a while that doesn't end.
EBGreen
-100. I said for loop.
-1000000. For loop isn't the way to do it.
ck