how do people feel about exit function from loop




In general,
How do people feel about using exit function from inside of a loop?
Is it bad practice?
So for example. The same code written 2 ways. Is the #1 bad code?
thanks


1)
For intCountElement = 1 To objConditionalFormats.Count
Set objFormatData = objConditionalFormats.Item(intCountElement)

If objFormatData.Format = strFormat Then
Set ConditionalFormatting_FindFormatData = objFormatData
Exit Function
End If

Next intCountElement
2)
Set ConditionalFormatting_FindFormatData = Nothing
intCountElement = 1
While ((intCountElement <= objConditionalFormats.Count) And
(ConditionalFormatting_FindFormatData Is Nothing))
Set objFormatData = objConditionalFormats.Item(intCountElement)

If objFormatData.Format = strFormat Then
Set ConditionalFormatting_FindFormatData = objFormatData
End If
intCountElement = intCountElement + 1
Wend







.



Relevant Pages

  • Re: how do people feel about exit function from loop
    ... How do people feel about using exit function from inside of a loop? ... For intCountElement = 1 To objConditionalFormats.Count ... Set objFormatData = objConditionalFormats.Item ... If objFormatData.Format = strFormat Then ...
    (microsoft.public.vb.general.discussion)
  • Re: how do people feel about exit function from loop
    ... Tony Proctor ... For intCountElement = 1 To objConditionalFormats.Count ... Set objFormatData = objConditionalFormats.Item ... If objFormatData.Format = strFormat Then ...
    (microsoft.public.vb.general.discussion)
  • Re: how do people feel about exit function from loop
    ... How do people feel about using exit function from inside of a loop? ... And in that case I would recommend Exit. ... For intCountElement = 1 To objConditionalFormats.Count ... Set objFormatData = ...
    (microsoft.public.vb.general.discussion)
  • Re: how do people feel about exit function from loop
    ... How do people feel about using exit function from inside of a loop? ... For intCountElement = 1 To objConditionalFormats.Count ... Set objFormatData = ... If objFormatData.Format = strFormat Then ...
    (microsoft.public.vb.general.discussion)
  • Re: how do people feel about exit function from loop
    ... For intCountElement = 1 To objConditionalFormats.Count ... Set objFormatData = objConditionalFormats.Item ... If objFormatData.Format = strFormat Then Exit For ... The code above does not work as it should: if the item is not found in the objConditionalFormats collection, it returns the last item in the collection! ...
    (microsoft.public.vb.general.discussion)