Regarding IF condition

Hi all,

Is there a way of writing the below python code with lesser lines in cpp.
1
2
3
if n == 6:
  var1 if x == 2 else var2,
  var3 if x == 3 else var4


Thank you
1
2
3
4
5
if (n == 6)
{
	((x == 2) ? var1 : var2);
	((x == 3) ? var3 : var4);
}


Though the returned variable is unused.

If you want it shorter then:

1
2
((n == 6 && x == 2) ? var1 : var2);
((n == 6 && x == 3) ? var3 : var4);
Last edited on
Thank you so much@zapshe
1
2
   pair<int,int> pr;
   if ( n == 6 ) pr = { x == 2 ? var1 : var2, x == 3 ? var3 : var4 };


Though, in python, you are probably returning it as an immutable tuple.
Last edited on
Thank you so much for your response. No I am not returning the variable.@lastchance
Topic archived. No new replies allowed.