Home > Back-end >  Is it possible to have an inline if with more than one expression per condition?
Is it possible to have an inline if with more than one expression per condition?

Time:03-29

Is it possible to have multiple expression in an inline if or do I necessarily need to use the traditional if statement this purpose?

widget.queueList[j] == 0 ? (jumpAround(); j ;) : widget.queueList[j]--;

The above is my code, is there a way for me to call jumpAround() and increment j in the same expression?

CodePudding user response:

Yes, you can do it like this:

void main() {
  int c = 0;

  c == 0 ? {print('c: $c'), c  , print('c: $c')} : {print('c: $c')};
}
  • Related