Jump to content
Xtreme .Net Talk

Recommended Posts

  • Leaders
Posted

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?

[sIGPIC]e[/sIGPIC]
Posted

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!

"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
Posted

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) :).

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

  • 2 weeks later...
Posted
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...

;)

Being smarter than you look is always better than looking smarter than you are.
  • Leaders
Posted

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?

[sIGPIC]e[/sIGPIC]
  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...