Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

working on a rails app that doesn't seem to want to run 'Until' or 'While' functions. Having to do the following:

<% if q == 2 or q == 5 or q == 8 or q == 11 or q == 14 or q == 17 or q ==20 %>

Any suggestions for how I can improve this?

share|improve this question

closed as off topic by Jeff Vanzella, Glenn Rogers, Brian Reichle, James Khoury, Corbin Dec 14 '12 at 2:35

Questions on Code Review Stack Exchange are expected to relate to code review request within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here. If this question can be reworded to fit the rules in the help center, please edit the question.

Try something like <% if q in [2,5,8,11,14,17,20] %> - not sure if ERB allows this though. –  Ash Dec 11 '12 at 21:07
OK that doesn't work. Try: <% if [2,5,8,11,14,17,20].include? q %> –  Ash Dec 11 '12 at 21:10
What are you trying to accomplish? A loop with a step of 3? In that case try (2..20).step(3) do ... end –  Flambino Dec 11 '12 at 22:22

1 Answer 1

If you really want to test these specific numbers, you could try

if (q % 3 == 2) && (q <= 20)
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.