Grasshopper

algorithmic modeling for Rhino

There must be a simple answer I'm overlooking:

I'm inside a For loop, and before I leave via Next, I want to check something.

- How do I sum all values (double or point3d) in a list up untill (i)?

Thanks for your reply,

Pim.

Views: 1126

Replies to This Discussion

I will assume that your i = list.count and before entering the loop the list is empty - if so, your for loop should look like :

Dim someList as new List(of double)

For i as integer = 0 to someList.count step 1

'some code

'adding values to list

If someList.count = 10 Then

Exit For

End If

Next

But it would be more elegant if you would use While loop :

Dim someList as new List(of double)

While someList.count <= 10

'some code

'adding values to list this is really important here

End While

Mateusz, thanks for your reply.

Probably I need to explain better:

I don't want to leave my For loop: I just want to check wether the sum of a certain value (point.Y) is not getting beyond another sum of values (doubles). (If it does, I'll operate on it some more)

I want this check done every instance of (i), but on the TOTAL: the summed list.

Therefor I need to "flatten" them or collapse, or mass addition to get the total. 

The SDK was my best friend the last weeks, but now...

I'am not sure if I understand you correctly, but let's give it a try :

Dim ptL as new List(of point3d)

Dim dbL as new List(of double)

Dim ptSum as double

Dim dbSum as double

For i as integer = 0 to 10 step 1

'add points to ptL if its empty

'add numbers to dbL if its empty

'sum ptL total 

ptSum += ptL(ptL.count-1).y 'this will add last ptL point y value to ptSum

'sum dbL total

dbSum += dbL(dbL.count-1) ' this will add last double to dbSum

If ptSum > dbSum then

'here you can operate some more :)

End If

Next

Of course, I knew I was overlooking.

I searched for a method to do this, but your solution is logical. 

Thanks a lot, it seems to work for me.

Pim.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service