Skip to main content
Code Review

Return to Answer

replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link
int v = b ? (a ? 1 : 2) : (a ? 0 : 1);

EDIT #1:

As per svick svick, parsed out conditional operator on separate lines:

int v = b
 ? (a ? 1 : 2)
 : (a ? 0 : 1);

EDIT #2:

Here's one I don't like, but it has no branching whatsoever:

int v = Convert.ToInt32(b) + Convert.ToInt32(!a);
int v = b ? (a ? 1 : 2) : (a ? 0 : 1);

EDIT #1:

As per svick, parsed out conditional operator on separate lines:

int v = b
 ? (a ? 1 : 2)
 : (a ? 0 : 1);

EDIT #2:

Here's one I don't like, but it has no branching whatsoever:

int v = Convert.ToInt32(b) + Convert.ToInt32(!a);
int v = b ? (a ? 1 : 2) : (a ? 0 : 1);

EDIT #1:

As per svick, parsed out conditional operator on separate lines:

int v = b
 ? (a ? 1 : 2)
 : (a ? 0 : 1);

EDIT #2:

Here's one I don't like, but it has no branching whatsoever:

int v = Convert.ToInt32(b) + Convert.ToInt32(!a);
added more stuff.
Source Link
Jesse C. Slicer
  • 14.5k
  • 1
  • 40
  • 54
int v = b ? (a ? 1 : 2) : (a ? 0 : 1);

EDIT #1:

As per svick , parsed out conditional operator on separate lines:

int v = b
 ? (a ? 1 : 2) : (a ? 0 : 1);

EDIT #2:

Here's one I don't like, but it has no branching whatsoever:

int v = Convert.ToInt32(b) + Convert.ToInt32(!a);
v = b ? (a ? 1 : 2 ) : (a ? 0 : 1);
int v = b ? (a ? 1 : 2) : (a ? 0 : 1);

EDIT #1:

As per svick , parsed out conditional operator on separate lines:

int v = b
 ? (a ? 1 : 2) : (a ? 0 : 1);

EDIT #2:

Here's one I don't like, but it has no branching whatsoever:

int v = Convert.ToInt32(b) + Convert.ToInt32(!a);
Source Link
Jesse C. Slicer
  • 14.5k
  • 1
  • 40
  • 54
v = b ? (a ? 1 : 2 ) : (a ? 0 : 1);
lang-cs

AltStyle によって変換されたページ (->オリジナル) /