Quantcast

Re: [julia-users] Equivalent for Python 'pass' statement in Julia

Previous Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [julia-users] Equivalent for Python 'pass' statement in Julia

Stefan Karpinski
On Tue, Jul 22, 2014 at 3:33 PM, <[hidden email]> wrote:
for i in testarray
    if testarray > 0
        do this
    else
        do nothing

Isn't this just equivalent to

for i in testarray
    if testarray > 0
        do this

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [julia-users] Equivalent for Python 'pass' statement in Julia

Matt Bauman


On Tuesday, July 22, 2014 6:33:42 PM UTC-4, [hidden email] wrote:
Sorry, not quite sure what the ? means -- does that mean 'or'? Also not sure about what you mean by the phrase ternary syntax.

Sure, the ternary operator — called that because of its three parts — is simply a shorthand for an if-then-else chain.  It's a common construct in many languages.  Wikipedia has lots to say about it: https://en.wikipedia.org/wiki/%3F%3A

In short, it allows you to say things like:

testarray > 0 ? do_this() : do_that()

I read it is "Is testarray > 0? Then do_this().  Otherwise, do_that()."  It's especially nice for inline assignments:

x = condition ? value_if_true : value_if_false

Loading...