Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

For Each Loop Exits Immediately

Tags:

vb6

I am converting a VB6 project to C#. I have come across some VB6 that I don't totally understand (and I don't have the ability to debug at all). It is a loop which exits immediately, before doing anything:

For Each objSubFolder In objFolder.SubFolders
  Exit For
Next

Can anyone explain that? I'm sure it does something. I'm guessing it is assigning a variable, or something. If so, does it do it only once?

like image 819
onefootswill Avatar asked Dec 13 '22 04:12

onefootswill


1 Answers

If objSubFolder exists outside the scope of the For Each (as per you comment), the code would be roughly the equivalent of this c#

var folders = Directory.GetDirectories(@"c:\someFolder");
var firstFolder=folders.FirstOrDefault();

i.e. find the first subfolder of a given folder (if it exists).

like image 106
Paolo Falabella Avatar answered Mar 08 '23 15:03

Paolo Falabella