mardi 27 avril 2021

Is it possible to create a list of numbers/letters in an if-statement without having to create multiple conditions?

(Probably noob-ish question by hey you live you learn)

So what I'm trying to do is make a list of values I want to check without having to create multiple conditions like you usually have to do:

if (a == 0 || a == 1 || a == 2 ... || a == 9) {
    // Code
}

Where you could probably do something like this:

if (a == (1,2,3,4,5,6,7,8,9)) {
    // Code
}

I couldn't find any posts on this topic and I once tried this myself at one point and it worked but nowadays it doesn't. Is it possible (Or still possible) to do something like this or in a way similar to this in an if-statement?

Aucun commentaire:

Enregistrer un commentaire