bri189a Posted September 29, 2004 Posted September 29, 2004 In C# you can: foreach(string s in MyStrings) Console.WriteLine(s); Note that s is declared on the spot, the closes I've been able to find for VB is the following: Dim s As String For Each s In MyStrings Console.WriteLine(s) Next s I much rather have: ForEach s as String In MyStrings Console.WriteLine(s) Next s because all the extra Dim lines in the middle of a function just to do a loop looks, feels, and smells sloppy, but putting them at the top of the function just looks messy. There has to be away to declare and use a variable in a loop in VB. I've noticed the same issue with a regular for loop. Quote
Administrators PlausiblyDamp Posted September 29, 2004 Administrators Posted September 29, 2004 For Each s As String In MyStrings Console.WriteLine(s) Next s as long as you are using vs 2003 or later Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
bri189a Posted September 29, 2004 Author Posted September 29, 2004 (edited) That's why it wouldn't work then...I have VB 2002. Will that work for iteration loop? For i As Integer = 1 To 10 Console.WriteLine(i) Next i (also how come my carriage returns aren't showing up in this code block?) Thanks! Edited September 29, 2004 by PlausiblyDamp Quote
Administrators PlausiblyDamp Posted September 29, 2004 Administrators Posted September 29, 2004 That will work as well! Did you cut and paste that from VS? If so are you using CRLF or just a CR as a line terminator? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
bri189a Posted September 29, 2004 Author Posted September 29, 2004 Actually I just typed it in. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.