Breaking out of several nested loops (& ANSI C)
hansen at pegasus.UUCP
hansen at pegasus.UUCP
Tue Oct 9 05:26:01 AEST 1984
One of the proposals that was supposed to be brought up before the last
committee meeting was a way to make breaking out of deeply nested loops
structured such that the following:
>> i=1;
>> while(...){
>> ...
>> for(...;...;...){
>> ...
>> switch(...){
>> ...
>> goto Out;
>> }
>> }
>> }
>> Out: i=2;
>>
would become:
>> i=1;
-- whileloop:
>> while(...){
>> ...
>> for(...;...;...){
>> ...
>> switch(...){
>> ...
-- break whileloop;
>> }
>> }
>> }
>> i=2;
>>
The idea is to be able to label while, for and do-while loops and be able to
use those labels on break and continue statements. This provides for a very
structured and much more readable and maintainable coding style, in my
opinion, than the equivalent code using goto's or separate procedures. This
feature is commonly called a "break n" capability in the literature and
other languages.
What does everyone think? Is this a worthy attempt at making the language
more structured and orthogonal? Send in your votes!
Tony Hansen
pegasus!hansen
More information about the Comp.lang.c
mailing list