Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I want to iterate over array only if it exists. Can this be a one-liner?
if array doSmth() for i in array
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...
Add a comment
For a short loop like that I think the postfix-if would be more idiomatic:
doSmth() for i in array if array
Required, but never shown
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.
Explore related questions
See similar questions with these tags.