Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:scriptsamples:vbcontinue [2015/09/14] (current)
Line 1: Line 1:
 +======Skipping current iteration of a VBScript For Loop======
 +> **Developer:​** //​[[developer:​rhinoscript|RhinoScript]]//​
 +> **Summary:​** //​Demonstrates how to skip the current iteration in a VBScript For loop.//
  
 +=====Question=====
 +Both C++ and C# have a **continue** statement that, when used with a **For** loop, skips the remaining statements of that iteration and moves on to next iteration. Does VBScript have anything like this?
 +
 +=====Answer=====
 +There is no **continue** or continue-like statement in VBScript. But using a **Do While** loop inside of a **For Each** statement, you can achieve the same functionality. For example:
 +
 +<code vb>
 +For i = 0 To 10
 +  Do
 +    If i = 4 Then Exit Do
 +    Rhino.Print i
 +  Loop While False
 +Next
 +</​code>​
 +
 +Here is another example.
 +
 +<code vb>
 +Sub TestContinue
 +  ​
 +  Dim arrTests, arrTest
 +  ​
 +  arrTests = Array( _
 +        Array(1) _
 +      , Array(1,2,3 ) _
 +      , Array(1,2) _
 +      , Array(1) _
 +      , Array(1,​2,​3) _
 +      )
 +      ​
 +  For Each arrTest In arrTests
 +     Call Rhino.Print("​Process:​ {" & Join(arrTest,​ ", ") & "​}"​)
 +     Do While True ' Continue trick
 +       Call Rhino.Print("​ Process: " & arrTest(0))
 +       If 0 = UBound(arrTest) Then Exit Do ' Continue
 +       Call Rhino.Print("​ Process: " & arrTest(1))
 +       If 1 = UBound(arrTest) Then Exit Do ' Continue
 +       Call Rhino.Print("​ Process: " & arrTest(2))
 +       Exit Do
 +     Loop
 +  Next
 +
 +End Sub
 +</​code>​
 +
 +{{tag>​Developer RhinoScript}}
developer/scriptsamples/vbcontinue.txt ยท Last modified: 2015/09/14 (external edit)