There are multiple ways to solve this - I'd recommend the last option, listed below:
The classical way is this way:
Sub ClassicalVersion()
For Each x In YourCollectionY 'or use For i = LBound(array) to Ubound(array)
If Condition1 Then
If Condition2 Then
If Condition3 Then
'Your code here
End If
End If
End If
Next
End Sub
This is sometimes referred to as the arrow-head antipattern and should be avoided imo, as it makes code hard to read.
Instead, you could go for a GoTo
statement:
Sub GoToVersion()
For Each x In YourCollectionY 'or use For i = LBound(array) to Ubound(array)
If Not Condition1 Then GoTo NextElement
If Not Condition2 Then GoTo NextElement
If Not Condition3 Then GoTo NextElement
'Your code here
NextElement:
Next
End Sub
A lot of people despise the use of GoTo
, but imo this would be a feasible solution to your problem and is already better to the classical version.
The best approach imo however is to separate the loop from your conditions (and according to the Single Responsibility Principle, maybe even the code from your condition check) using a sub routine and the Exit Sub
statement:
Sub SRPVersion()
For Each x In YourCollectionY 'or use For i = LBound(array) to Ubound(array)
If RunChecks Then
CallToSubWithYourCode
End If
Next
End Sub
Function RunChecks(x as ...) as Boolean
If Not Condition1 Then Exit Function
If Not Condition2 Then Exit Function
If Not Condition3 Then Exit Function
RunChecks = True
End Function