[Python-ideas] loop, breakif, skip

Jim Hill jim_hill_au-24 at yahoo.com.au
Sun Sep 9 09:24:47 CEST 2007


These 4 proposals are somewhat inter-dependent,
so I include them in a single message.

They are simple ideas, childish almost.
Think of non-programmers writing simple scripts,
and children learning basic coding in grade school.

Hope I'm not wasting your time with nonsense.
(I'm not an advanced programmer, so can't be sure.)

------------

Proposal 1

Abolish 'continue' in loops, and use 'skip' instead.

In normal English 'continue' means 'carry on at the next line'.

In most programming languages 'continue' means
'jump back UP the page to the start of this loop'.

This is OK for programmers accustomed to C, but
I find it very counter-intuitive, even though
i know it means 'continue with the next iteration'.

On the other hand, 'skip', meaning
'skip the rest of this iteration',
feels more intuitive to me.

'continue' is too long, 'skip' is short.

One new keyword.
Breaks existing code.

------------

Proposal 2

an alternative to PEP-315, and a simpler way
to write while loops of various flavours.

part A

'loop:' is exactly equivalent to 'while True:'

part B

(1)
'*breakif <condition>'
is exactly equivalent to
'if <condition>: break'

(2)
'*skipif <condition>'
is exactly equivalent to
'if <condition>: skip'

(assuming 'skip' replaces 'continue')

* is to make the word easier to find by human eye.
would some other character do it better?

2a and 2b together allow while loops to optionally
look something like this:

loop:
    <statements>
    *breakif <condition>
    <statements>
    *skipif <condition>
    <statements>


*breakif and *skipif can be used in for loops too, of course.

3 new keywords.
Existing code would not be affected, unless it was
already using loop, *breakif or *skipif as names.

------------

Proposal 3

Mainly for young students learning to program.

the keyword 'loop' can be placed in front of the keyword 'while'
the keyword 'loop' can be placed in front of the keyword 'for'
without changing the meaning of 'while' or 'for'.

Looks like this

loop while <condition>:
    <statements>

loop for <iteration expression>:
    <statements>


Allows beginner students the satisfaction of thinking that
every kind of loop begins with the word 'loop',
which also makes learning a little easier.
(Later they will learn that 'loop' can be left out.)

Existing code would not be affected.

------------

Proposal 4

If 'continue' is not used in loops, it can have
a more meaningful role in switch/case blocks.

'continue' in a Python switch block would have a meaning
opposite to that of 'break' in a C switch block,
allowing you to do 'fall-through'.

Here 'continue' would have its intuitive meaning of
'carry on at the next line'.


switch <expression>:
    case <values>:
       <statements>
       [continue]
    case <values>:
       <statements>
       [continue]
    case <values>:
       <statements>


Existing code would not be affected,
as switch/case is not implemented yet.

------------

Jim Hill




More information about the Python-ideas mailing list