Leaders snarfblam Posted July 6, 2004 Leaders Posted July 6, 2004 This is something ive been wondering a very long time (perhaps years) but have never investigated. Is there ANY difference programatically, in compilation, or any other kind of difference between a Do While...Loop and a While...While End? Quote [sIGPIC]e[/sIGPIC]
Arch4ngel Posted July 6, 2004 Posted July 6, 2004 Hummm I think it's kept for compatibility issues. I know their is a difference between Do... While and While... Do (am I right ? huhu). But ... I think they kept that for compatibility with VB6 language. I recommend using While While End. Have a nice day! Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
Leaders Iceplug Posted July 6, 2004 Leaders Posted July 6, 2004 Do While ... Loop and While ... End While are the same thing. I'd assume that they compile to the same assembly instructions. The While ... End While is sort of like a special version of the Do While ... Loop, since other languages like C have while loops and this would be easily distinguishable as the VB equivalent, but other than that, I use the Do Loop all of the time... Because you can also have the While condition at the bottom (Do ... Loop While). And then, you can have a Do Until ... Loop which is the opposite of the While loop, and you can also move the Until to the bottom (Do ... Loop Until) :). Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
Mothra Posted July 20, 2004 Posted July 20, 2004 Because you can also have the While condition at the bottom (Do ... Loop While). And then, you can have a Do Until ... Loop which is the opposite of the While loop, and you can also move the Until to the bottom (Do ... Loop Until) :). That is the difference. One loop checks for a condition at the "top" of the loop and the other checks it at the "bottom" of the loop. I can't remember which one does which exactly though...late at night, not enough caffeen...powers...weakening... ;) Quote Being smarter than you look is always better than looking smarter than you are.
Leaders snarfblam Posted July 21, 2004 Author Leaders Posted July 21, 2004 Come on guys. I asked if there was a difference between a Do While...Loop and a While...While End, not Do Loops and While Loops in general. All this i know: You can have a Do While... Loop, a Do Until...Loop, Do...Loop While and Do...Loop Until. While... End While appears to be identical to Do While... Loop, which is why I question it's being. What I dont know: Is there ANY difference programatically, in compilation, or any other kind of difference between a Do While...Loop and a While...While End? Quote [sIGPIC]e[/sIGPIC]
Administrators PlausiblyDamp Posted July 21, 2004 Administrators Posted July 21, 2004 Did a quick test: Public Sub test1() Dim i As Integer = 3 While i < 100 i += 1 End While End Sub Public Sub test2() Dim i As Integer = 3 Do While i < 100 i += 1 Loop End Sub both produced the same MSIL { // Code size 14 (0xe) .maxstack 2 .locals init (int32 V_0) IL_0000: ldc.i4.3 IL_0001: stloc.0 IL_0002: br.s IL_0008 IL_0004: ldloc.0 IL_0005: ldc.i4.1 IL_0006: add.ovf IL_0007: stloc.0 IL_0008: ldloc.0 IL_0009: ldc.i4.s 100 IL_000b: blt.s IL_0004 IL_000d: ret } no difference between them. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Leaders snarfblam Posted July 27, 2004 Author Leaders Posted July 27, 2004 Wow. A very straightforward and helpful answer. I'm surprised. Thank you very much, PlausiblyDamp. Quote [sIGPIC]e[/sIGPIC]
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.