0

Need help, my code has a lot of expressions in if statement and I'm trying to get rid of it or organize it in a better way.

for example like this:

if (fieldNumber==1 && (language=='en' || language=='fr' || language == 'de')){
    code
}

if (fieldNumber==1 && ((language == secondLanguage && language == 'en')|| country == 'PO'){
    code
}
2

Implying that your functionality will be expanded I would propose something like that:

List<String> languages = new List<String>{'en', 'fr', 'de'};
String eng = languages[0];

if(fieldNumber == 1){

    if(languages.contains(language)){
       //code
     }

    if((language == eng && secondLanguage == eng) || country == 'PO'){
       //code
     }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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