Re: Variable Scope

From: Date: Sat, 30 Aug 2003 14:51:07 +0000
Subject: Re: Variable Scope
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-4272@lists.php.net to get a copy of this message
On Saturday, Aug 30, 2003, at 10:33 America/New_York, Derick Rethans wrote:
On Sat, 30 Aug 2003 LingWitt@insightbb.com wrote:
Since the inner loop declares $i again, it should mask the outer loop's $i as per other languages. Besides being useful, it makes more sense.
No, that's not true. You don't redeclare ANYTHING here... you're just using the same variable $i, just like you would do in C.
//In the following example, the inner loop 'i' masks the outer loop 'i': int array[] = {1, 2, 3, 4, 5}; for (int i = 0; i < 5; i++) {
        int num = array[i];
        printf("%d", num);
        for (int i = 0; i < 5; i++)
                printf("%d", i * num);
}
Otherwise, the declaratory statement in the second loop is completely meaningless.
You don't declare anything... Derick -- "Interpreting what the GPL actually means is a job best left to those
                    that read the future by examining animal entrails."
-------------------------------------------------------------------------
 Derick Rethans                                 http://derickrethans.nl/
 International PHP Magazine                          http://php-mag.net/
-------------------------------------------------------------------------
--PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.internals (#4272) next »