suggested improvements to D

BCS ao at pathlink.com
Tue Jan 9 11:07:44 PST 2007


Reply to Warren,

> reply to BCS's reply
> 
> actually you meant this:
> loop: do{
> for(some loop condition){
> if(something) break loop;
> }
> fallthru_code;
> }while(false);
> break_out_code;
> 

Oops.

[...]
> So your suggestion for this syntax is a good one:
> bod: {     // labeled compound statement
> if(cond) break bod;
> }
> except I do not see the point (or syntactical meaning,
> for that matter) of having "continue bod" if bod is not
> manifestly a loop.   

The thought is it would be the same as in a while(true), go back to the start 
of the loop. It could be handy with some kids of loops

// keep (re)doing things in order until all conditions are met.

bod: {
	//somthing
	if(cond1) continue bod;
	//somthing
	if(cond2) continue bod;
	//somthing
	if(cond3) continue bod;
	//somthing
	if(cond4) continue bod;
}

this would work but isn't as informative.

while(true){
	//somthing
	if(cond1) continue bod;
	//somthing
	if(cond2) continue bod;
	//somthing
	if(cond3) continue bod;
	//somthing
	if(cond4) continue bod;
	break;
}


> This simple suggestion of being
> able to break out of any block, would
> eliminate practically all the remaining gotos in the world.
> Excellent idea.





More information about the Digitalmars-d mailing list