Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108760 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 32436 invoked from network); 25 Feb 2020 21:30:10 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 25 Feb 2020 21:30:10 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 451071801FD for ; Tue, 25 Feb 2020 11:47:39 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS1836 195.49.0.0/17 X-Spam-Virus: No X-Envelope-From: Received: from darkcity.gna.ch (darkcity.gna.ch [195.49.47.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 25 Feb 2020 11:47:38 -0800 (PST) Received: from flatter.home (unknown [IPv6:2a02:120b:2c4e:2460:2c36:b7a1:6187:d62c]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by darkcity.gna.ch (Postfix) with ESMTPSA id 10CAC6C1524; Tue, 25 Feb 2020 20:47:36 +0100 (CET) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3608.60.0.2.5\)) In-Reply-To: Date: Tue, 25 Feb 2020 20:47:35 +0100 Cc: PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: <266AC937-7C89-4438-9581-A7BDB5D40F6F@cschneid.com> References: To: Michael Morris X-Mailer: Apple Mail (2.3608.60.0.2.5) Subject: Re: [PHP-DEV] Thoughts on adopting Python's for/foreach else construct. From: cschneid@cschneid.com (Christian Schneider) Am 25.02.2020 um 20:18 schrieb Michael Morris : > How difficult would it be to make the following work in the = interpreter? >=20 > foreach($a as $key =3D> $value) { > // code for iteration > } > else { > // code for no results > } > ?> >=20 > The code of the else clause executes if the foreach is never entered > regardless of the reason (provided the code didn't outright crash) I like the idea. And I think it makes more sense than what Python actually does: With Python the else clause is executed if the loop is not exited with a = break. https://book.pythontips.com/en/latest/for_-_else.html So, yes, I would like a foreach .. else but not the Python way ;-) - Chris