in reply to Re^5: Nesting Functions
in thread Nesting Functions

> Example?

fruits = ["apple", "banana", "cherry"] for x in fruits: print(x) if x == "banana": print(y) if x == "apple": y=1

whips himself

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^7: Nesting Functions
by LanX (Saint) on Jul 19, 2019 at 14:22 UTC
    what's your point?

    >>> fruits = ["apple", "banana", "cherry"] >>> for x in fruits: ... print(x) ... if x == "banana": ... print(y) ... if x == "apple": ... y=1 ... apple banana 1 cherry

    Probably you don't like the "hoisting" of the binding of y?

    Please note that JS is also doing hoisting even that it has a var statement°

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

    °) and now even let which behaves (almost completely) like my in Perl