1. NodeBox 1
    1. Homepage
    2. NodeBox 3Node-based app for generative design and data visualization
    3. NodeBox OpenGLHardware-accelerated cross-platform graphics library
    4. NodeBox 1Generate 2D visuals using Python code (Mac OS X only)
  2. Gallery
  3. Documentation
  4. Forum
  5. Blog

conditionals :: absolute equality

Posted by _brentonW on Jun 12, 2009

Can anyone tell me if nodebox allows the equality operator [ == ]? or an alternate for an if statement?

I want to run some code at the end of a "for" statement with an "if" statement to run when [ i ] and 'range' are equal.

Using the "==" equality symbol throws an error.

Any suggestion to an alternate solution would be appreciated.

Example:

for i in range(9):
    [code to run 9x]
    if i == range
        [code to do at end but throws error]


 
Posted by _brentonW on Jun 12, 2009

A bit of digging around nodebox revealed that I had the syntax wrong. I believe I have corrected that however am unable to prove it by a simple print action.

Example

for i in range(9):
    [code to run 9x]
    if (i == range):
        print "true"
While I am able to syntactically set up the "if" statement it doesn't run.

Thoughts/suggestion?



Posted by Stefan on Jun 12, 2009

This won't work because you're comparing a number (i) to a function (range). The two can be compared however they will always return False.

Since the function range generates a list of numbers, what you really want to do is compare i to to some item in this list, the last item in your case. The last item in a list is somelist[-1]

So the code becomes something like this:

myrange = range(9)
for i in myrange:
    # code to run 9x
    if i == myrange[-1]:
        print "true"



Posted by Lucas on Jun 12, 2009

Or this way, remember the range starts counting from zero.

anynumber = 9
for i in range(anynumber):
    print "coderun:", i + 1
    if i + 1 == anynumber:
        print "the last run: ", i + 1



Posted by _brentonW on Jun 14, 2009

ahhh.
I see.

Thanks for the help.
Really appreciate it.