#Simplify long conditional

7 messages · Page 1 of 1 (latest)

latent sentinel
#

Okay I'm sure this is an extremely dumb question but I A: was never trained with something like this and B: Have no clue how to even ask this question to google

Is there a more simple/compact way to do this:

        if(scan[itr] == '#' || scan[itr] == '%' || scan[itr] == '&' || scan[itr] == '{' || scan[itr] == '}' || scan[itr] == '\\' || scan[itr] == '<' || scan[itr] == '>' || scan[itr] == '*' || scan[itr] == '?' || scan[itr] == '/' || scan[itr] == '$' || scan[itr] == '!' || scan[itr] == '\'' || scan[itr] == '\"' || scan[itr] == ':' || scan[itr] == '@' || scan[itr] == '+' || scan[itr] == '`' || scan[itr] == '|' || scan[itr] == '=')
        {
            //condtion to be executed
        }

Sorry if this is aneurysm inducing 😭

sharp marshBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

main vigil
#
std::array acceptedValues{....}
if (contains(acceptedValues, scans[itr])
  // do thing
tropic summit
#

No idea about the rest of your code so I can't offer potentially better solutions, but if it's just this in isolation then you could do

switch (scan[itr]) {
case '#':
case '%':
case '&':
case '{':
// ...
case '=': {
    codeIfTrue();
    break;
}
}
latent sentinel
#

Thank you both sorry for having you see that nightmare lmao, i was attmepting to make something that removes any illegal charecters from a string and in my bout of sleep deprevation that was my bright idea, might go with the array method since this is being added to a public project and i dont want to give any one else a migraine lol

#

!solved