|
-
May 14th, 2010, 06:16 PM
#1
Thread Starter
New Member
Number of Loops
Silly question perhaps, but I am in a debate with a professor to actually how many different loops there are in Visual Basic.
He is saying there are only 2.
Do Loops
For Next Loops
I am making a case since a While..End While Loop is unique since it can be written without any indication of the DO statement. This makes it a unique loop because of its unique syntax.
What is the opinion of the users here ?
-
May 14th, 2010, 06:27 PM
#2
Re: Number of Loops
While is deprecated, as it doesn't sport any loop exit statement, and only supports a condition in the first While statement. There's Exit For and Exit Do, but no Exit While.
There's also no 'End While', the term is Wend.
While/Wend is merely supported for backwards compatibility, DO/LOOP is the suggested replacement.
There's, I suppose, technically a forth syntax and method for looping. Using the For Each statement.
Then, of course, you can do it 'manually' with GoTo.
Perhaps he means there are two proper ways to loop (assuming For/Next encompasses For Each(they both make use of Exit For, and Next)).
-
May 14th, 2010, 07:38 PM
#3
Thread Starter
New Member
Re: Number of Loops
According the the microsoft web site, there is a end statement for While.
http://msdn.microsoft.com/en-us/library/zh1f56zs.aspx
-
May 14th, 2010, 07:51 PM
#4
Re: Number of Loops
 Originally Posted by nofrills
Judging by the example code I'd say that is for .Net, because
counter += 1
is not valid in VB Classic.
Also, initializing a variable like: Dim counter As Integer = 0 is not correct, plus you close a While loop with Wend, not End While.
-
May 14th, 2010, 08:05 PM
#5
Thread Starter
New Member
Re: Number of Loops
I appreciate these responses. I am not trying to disprove anyone here, but a smarty Professor and his snippy comments to the students.
I am using Visual Studios 2008 designing a Visual Basic Form. I used the code example from above and it worked just fine. I have to assume that when I wrote this code it was for visual basic and not .net
Am I wrong?
Last edited by nofrills; May 14th, 2010 at 08:12 PM.
-
May 14th, 2010, 08:12 PM
#6
Re: Number of Loops
If you are using Visual Studio 2002 or newer (which you are) then you are definitelly working with VB.Net so the sample on the website you have posted applies and works for you. And, if that is the case, you posted the question on the wrong forum since this is for VB Classic (that's why we were telling you that you were wrong, since that doesn't work for older VB6 ) I'll notifiy the mods to move the thread to the .Net section so you don't have to repost.
-
May 15th, 2010, 03:49 AM
#7
Re: Number of Loops
Thread moved from 'VB6 and Earlier' forum to 'VB.Net' (VB2002 and later) forum
(thanks as always baja_yu )
-
May 15th, 2010, 04:03 PM
#8
Re: Number of Loops
For VB.NET, the loops are:
For...Next
Do...Loop
While...End While
For Each...Next
And there are Exit statements for all of them, and none of them are deprecated, no matter how many people say it.
-
May 17th, 2010, 12:42 PM
#9
Thread Starter
New Member
Re: Number of Loops
In my visual basic class, I am still getting smacked around by the professor and some students telling me there are only two loops.
I am holding fast to my inital answer of 3, For Each making it 4 , regardless how many points I loss in the class for it. Truth is truth, and they are all wrong.
-
May 17th, 2010, 01:05 PM
#10
Re: Number of Loops
You're losing points for it??? Ok, just give a code example using While to everyone.
-
May 17th, 2010, 02:30 PM
#11
Re: Number of Loops
Aren't we just picking nits?
Are these the same or different loops
do while true
loop
do
loop while true
And isn't
For Each just a form of For value = initialcount to stopcount?
-
May 17th, 2010, 02:32 PM
#12
Re: Number of Loops
Fundamentally there are two (three with goto). There are many variations of those two, but I would suspect that if you looked at the IL for two examples, they would be close.
-
May 17th, 2010, 04:08 PM
#13
Re: Number of Loops
For Each will generate completely different IL to use the IEnumerator interface, so I classify it as another type of loop. While is the same as Do when the condition for the Do is at the start of the loop. So there are 3 and a half.
-
May 17th, 2010, 06:17 PM
#14
Re: Number of Loops
 Originally Posted by minitech
For Each will generate completely different IL to use the IEnumerator interface, so I classify it as another type of loop. While is the same as Do when the condition for the Do is at the start of the loop. So there are 3 and a half.
That is a surprise.
I knew the difference in the do loops.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|