Reputation: 1656
I have multiple variables which needs the same check in a if-statement in Dart. I need to know if there is at least one of the variables > 0.
For example:
var a = 1;
var b = 0;
var c = 0;
if ((a > 0) || (b > 0) || (c > 0)) {
print('Yeh!');
}
This should be done easier, like in Python.
The following code isn't valid, but I tried this:
if ((a || b || c) > 0) {
print('Yeh!');
}
Any tips would be nice.
Upvotes: 6
Views: 3440
Reputation: 90125
One way would be to create a List
and to use Iterable.any
:
if ([a, b, c].any((x) => x > 0)) {
print('Yeh!');
}
Upvotes: 4