Inline If statement

In order to save the lines of code instead of using the typical if else we can use inline if statment:

skeleton is (a condition b ? do this() : do that())

ex1:

a=5;

(a>3 ? peal() : leave())

In above example a will be checked if it’s bigger than 3 if so run peal() if not run leave()

ex2:

getAge(a>3 ? a=10: null)

in above example if a more than 3 then a will be assigned to 10 if not then get will run with value null.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s