Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 557067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:59:12+00:00 2026-05-13T11:59:12+00:00

This is more a question of semantics than anything else. I’d like to check

  • 0

This is more a question of semantics than anything else.

I’d like to check if a variable is either one of two values. The easiest way of doing this would be:

if var == "foo" || var == "bar"
# or
if var == 3     || var == 5

But this doesn’t feel very DRY to me. I know I can use String.match(), but that doesn’t work for non-string variables and is three times slower.

Is there a better way of checking a variable against two values?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T11:59:12+00:00Added an answer on May 13, 2026 at 11:59 am

    Put all values into an array and then it should be easy.

    %w[foo bar].include?('foo') # => true
    
    [3,5].include?(3) # => true
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is more a curiosity question than a pressing one. This question is looking
This is more a curiosity question than anything. Say I supply a LinkedHashMap with
This is more like a question of principle. I made a table with 100%
this is more of an algorithmic question rather than a specific language question, so
The question I have might be more to do with semantics than with the
This question is more a semantic-algorithmic-data-structure question than a F# syntactically question. I have
This is more of a conceptual question than an actual implementation and am hoping
This is a rather simple question more or less considering syntax semantics. I've got
EDIT: This question is more about language engineering than C++ itself. I used C++
This is more a question of pros/cons between PHP and JAVA. Iv been doing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.