I have a code where I want an if statement with 3 conditions passed. However, in one of my conditions, I can allow either or.
For example, the if statement is true if( 5 && 6 && (7||9||10||12))
.
So 5,6,10 would be true, but 5,6,13 wouldn't.
I have a code in ruby with this similar logic but it is giving me syntax errors (maybe because of an extra parenthesis). However, I was wondering if this logic is allowed.
if (constraintsHashed[i][DINING_CONSTRAINTS].downcase.include? userDiningOptions) && (constraintsHashed[i][COST_CONSTRAINTS].downcase.include? userBudget) &&
(((userTime >= Time.parse(TENAM)) && userTime <= Time.parse(NINEPM)) or (userTime >= Time.parse(SEVENAM) && userTime <= Time.parse(TWELVEAM)) or
(userTime >= Time.parse(SEVENAM)) && (userTime <= Time.parse(FIVEPM)) or (userTime >= Time.parse(NINEAM)) && (userTime <= Time.parse(SIXPM)) or
(userTime >= Time.parse(TWELVEPM)) && (userTime <= Time.parse(TWELVEAM)) or (userTime >= Time.parse(TENAM)) && (userTime <= Time.parse(ELEVENPM)))
Stack trace:
diningHall.rb:132: syntax error, unexpected keyword_else, expecting ')'
diningHall.rb:134: syntax error, unexpected keyword_end, expecting ')'
end #End for if(constraintsHashed
^
diningHall.rb:141: syntax error, unexpected keyword_end, expecting ')'
end #End for def weekendOptions
^
diningHall.rb:269: syntax error, unexpected end-of-input, expecting ')'
main() #Program starts here
^