Nested If

Not sure why this gives an error?

x= int(event.source.text)
y = int(event.source.parent.getComponent(‘qty’).text)

if (x <= y):
elif (x >= 5):
event.source.validsp1tot = 1

else:
event.source.validsp1tot = 0

Somehow I lost the indentations on the previous posting??

x= int(event.source.text)
y = int(event.source.parent.getComponent(‘qty’).text)

if (x <= y):
elif (x >= 5):
event.source.validsp1tot = 1

else:
event.source.validsp1tot = 0

did you mean?

x= int(event.source.text)
y = int(event.source.parent.getComponent('qty').text) 

if (x <= y):
    if (x >= 5):
        event.source.validsp1tot = 1

    else:
        event.source.validsp1tot = 0

otherwise your if(x<=y) statement does not evaluate to anything because there is nothing in its indented block.

Hi DB2,

Well, here’s the obligatory ‘what error are you getting?’

Second, you meant this, right? Use ‘code’ blocks instead of ‘quote’ if you want to see the indentation.if (x <= y): elif (x >= 5): event.source.validsp1tot = 1 else: event.source.validsp1tot = 0

And the error you are getting is probably due to the fact that you have nothing after that first ‘if’. You have to put something between the if and elif for the code to compile correctly. if you really want it to do nothing, you can use the keypord pass.

So it would look like:if (x <= y): pass elif (x >= 5): event.source.validsp1tot = 1 else: event.source.validsp1tot = 0

So that will do the following: If x<=y, then do nothing. If x>y and x>=5, then set validsp1tot = 1. If x>y and x<5 then set validsp1tot = 0. Is this what you intended?