<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
Let’s go back to why we have the ternary expression in the first place. Contrary to popular belief, it is *not* for syntactic concision.
<div class=""><br class="">
</div>
<div class="">The difference between</div>
<div class=""><br class="">
</div>
<div class=""> int x;</div>
<div class=""> If (b) </div>
<div class=""> x = a;</div>
<div class=""> else</div>
<div class=""> x = b;</div>
<div class=""><br class="">
</div>
<div class="">and</div>
<div class=""><br class="">
</div>
<div class=""> Int x = b ? a : b</div>
<div class=""><br class="">
</div>
<div class="">Is that the latter is a _more constrained_ construct than the former. In the former, the then/else blocks of the if can contain arbitrary statements, and there is no way (other than DA/DU analysis) to capture the intention that we will assign
to x in each arm (or even that there are both arms.) Whereas the latter is an _expression_, and expressions are _total_. So the latter makes use of a more constrained mechanism, and therefore allows for richer type-checking. The concision is merely a bonus.
</div>
<div class=""><br class="">
</div>
<div class="">Your proposal conflates statements and expressions; the ternary conditional is an expression, whose arms are expressions, but you want to use a version of it for statements. And why? So you can type *two fewer characters*. It offers no additional
type checking, introduces a gratuitously different way to do the same thing, and creates the Frankenstein monster of an operator that is really a statement. And it doesn’t result in more readable code; arguably, less readable, since we’re less use to spotting
side-effects nestled in what look like expressions. </div>
<div class=""><br class="">
</div>
<div class="">If you mean “if (condition) do stuff”, then there’s no shame in saying exactly that. </div>
<div class=""><br class="">
</div>
<div class="">
<div><br class="">
<blockquote type="cite" class="">
<div class="">On Aug 23, 2022, at 2:28 PM, sankar singh <<a href="mailto:sankar.singu@gmail.com" class="">sankar.singu@gmail.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div dir="ltr" class="">Hi Team,
<div class=""><br class="">
</div>
<div class="">We are using ternary operator</div>
<div class=""><br class="">
</div>
<div class="">
<div class="">
<div class="">Can we use single conditional code like the below.</div>
<div class=""><br class="">
</div>
<div class=""><b class=""><font size="4" class="">if (a>50)</font></b></div>
<div class=""><b class=""><font size="4" class=""> print("50 more")</font></b></div>
<div class=""><b class=""><font size="4" class=""><br class="">
</font></b></div>
<div class=""><b class=""><font size="4" class="">a>50?. print("50 more")</font></b></div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
-- <br class="">
<div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"> <br class="">
regards,<br class="">
<br class="">
Shankar.S<br class="">
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</body>
</html>