Jump to content

Photo

Checking for multiple conditions


  • Please log in to reply
4 replies to this topic

#1
greyday01

greyday01

    Old hand

  • Premium Member
  • 703 posts

If you are checking for half a dozen or so conditions on an event would you use nested if / then's or a long if with multiple and checks on the same line?

 

This won't be running continuously or even frequently so speed would not be really an issue.



#2
IsharaMeradin

IsharaMeradin

    The Pale Redguard

  • Members
  • PipPipPipPipPip
  • 10,664 posts

Nesting might be easier with regards to testing.  You would be able to return notification or trace statements at each valid condition.  Thus finding out if a particular condition doesn't yield the results expected.

 

After testing, switching to a multi-line (separated by / ) may be easier to see what is intended to happen after having put the project down for some time.



#3
scorrp10

scorrp10

    Old hand

  • Premium Member
  • 701 posts
I would say,  split it into multiple lines
 
if ( condition1 && \
     condition2 && \
     condition3 && \
     condition4)
    ...
endif


#4
greyday01

greyday01

    Old hand

  • Premium Member
  • 703 posts

Thank you. I never knew about the backslash to make a single line of script be split among several lines.



#5
IsharaMeradin

IsharaMeradin

    The Pale Redguard

  • Members
  • PipPipPipPipPip
  • 10,664 posts

Thanks for the example scorrp10.  I was clearly not thinking and indicated the wrong slash to use...






IPB skins by Skinbox
Page loaded in: 0.449 seconds