Grasshopper

algorithmic modeling for Rhino

How can I do this "go to for loop again":

here is the pseudo code:

'get all the circles with radius smaller than 10
for i=0 to N
   check radius for one circle
   if  radius>10
      go to for loop again to check next circle
   end if
  
   circlesList.add(theCircle)
next


Views: 648

Replies to This Discussion

'pseudocode edit to the pseudocode
'get all the circles with radius smaller than 10
for i=0 to Number of Circles
'check radius for one circle
if circles(i).radius<10
'add the circle to the list
circlesList.add(circles(i))
end if
' go to for loop again to check next circle

next

maybe that is what you want?
Luis:

Thx for your quick help. But this is not what I need. I properly didn't explain my needs well. You simplified my code and make it more precise. However I am looking for sth like goto statement.
Here is one example in using goto statement:


public class MainClass
Shared Sub Main()
Dim counterVariable As Integer = 0

repeat: ' the label
Console.WriteLine("counterVariable: {0}", counterVariable)

' increment the counter
counterVariable += 1

If counterVariable < 10 Then
GoTo repeat ' the dastardly deed
End If
End Sub

End Class
I think you're somewhat confused. Luis's code is correct in the sense that it will only add the circles who's radius is less than the number to the list, which sure seams like your asking about.

Anyway, I don't think that GoTo statements are really supported in GH's situation. In order to use GoTo statements you actually have to label the appropriate line that you're going to, and I'm not sure that that's really supported in a runtime compiled situation.

You may also be interested in the Continue statement, which you can put in a For/Do/While structure and will force the code to go back to the top of that control structure. Ultimately this can pretty much be achieved with If...Then statements, or even Case statements, but it is there if need be.
I am trying this, it works. This is a testing code. I will kill myself if I can't get my formal code works:

Dim i As Integer
For i = 0 To 9
If x = 3 Then
print("The number is 3.")
If x <> 3 Then Continue For
End If
Next

actually for performance issue, I should put "the continue for " on the first:

Dim i As Integer
For i = 0 To 9
If x <> 3 Then Continue For
If x = 3 Then
print("The number is 3.")
End If
Next
Actually, for the performance issue, you should not use the second If...Then statement and just use Else.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service