1

I want to iterate over array only if it exists.
Can this be a one-liner?

if array
    doSmth() for i in array

2 Answers 2

1

hha! I've just discovered that I can do this

if array then doSmth() for i in array

And also this

if array then for i in array
        foo = 1
        bar = 2
        baz = 3

So simple...

Sign up to request clarification or add additional context in comments.

Comments

1

For a short loop like that I think the postfix-if would be more idiomatic:

doSmth() for i in array if array

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.