A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2001-April/078027.html below:

Named code blockes

Named code blockesCarlos Ribeiro cribeiro at mail.inet.com.br
Sat Apr 14 19:22:55 EDT 2001
At 16:55 14/04/01 -0400, Steven D. Majewski wrote:
>( But maybe you're thinking of a different syntax for Python
>   than I can imagine from other lang. I've seen. If you show
>   me a clear example, I'll reconsider. )

I've came up with a example. The actual code does nothing useful (it's 
non-sense :-), but it serves to show one possible syntax:

for i in list1 as Loop1:
     for j in list2 as Loop2:
         if j in list1:
             continue Loop1
         for k[j] in list3 as Loop3:
             if k[j] in list1:
                  break Loop1

The label is specified by the "as label" construct right after the loop 
statement. Both break and continue could take an optional parameter to 
specify the loop to which they do refer.

The word "as" is already used in the import statement. In this case, it 
would specify a label for the break and continue statements. "as" doest not 
need to me made a reserved word, because it can appear only in a well 
defined context. Optionally, the word "label" could also be used:

for i in list1 label Loop1:
     (...)

Two things called my attention while writing the simple example above:

- *In my example*, the "continue Loop1" statement will have exactly the 
same effect as a "break" statement. In fact, in many cases the effect will 
be the same. If you don't have any extra logic after the inner loop, both 
"break" and "continue label" will be equivalent.

- There are some similarities between these labeled break/continue 
constructs and continuations. One possible implementation for this kind of 
construct would be the use of one type continuations. The Stackless people 
could clarify this a little bit better for me.


Carlos Ribeiro




More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4