Why not allow empty code blocks?

Chris Angelico rosuav at gmail.com
Sat Jul 30 12:34:27 EDT 2016


On Sun, Jul 31, 2016 at 1:48 AM, Steven D'Aprano <steve at pearwood.info> wrote:
> Hypertalk (and related XTalk languages) offer a number of dedicated looping
> constructs. Using square brackets [] for optional terms:
>
> repeat [forever]
> repeat [for] number [times]
> repeat until condition
> repeat while condition
> repeat with variable = start [to] end
> repeat with variable = start [down to] end
>
>
> That's right, a bare "repeat" on its own gives you an infinite loop. Does
> *your* language have special syntax for infinite loops? If not, why not?

Hmm, very similar to REXX, with one critical difference. Here's REXX's loops:

do
do forever
do number
do while condition
do until condition
do variable = start [to end] [by step] [for count]

In REXX, "do forever" is like Hypertalk's "repeat forever", and the
other constructs are similar (though the counted form is more flexible
- you can say "do i=1 to 10" to set the end marker, or you can say "do
i=1 for 10" to set an iteration count) - but "do" on its own means
"execute this block of code exactly once", not an infinite loop.
(do/end in this form is for defining blocks of code, like Pascal's
begin/end or C's { }.) Curious distinction.

ChrisA



More information about the Python-list mailing list