do-while loops

Xinok xinok at live.com
Wed Dec 28 08:02:39 PST 2011


On 12/28/2011 8:29 AM, bearophile wrote:
> One thing that I often find not handy in the design of do-while loops: the scope of their body ends before the "while":
>
>
> void main() {
>      do {
>          int x = 5;
>      } while (x != 5); // Error: undefined identifier x
> }
>

I would just rewrite it like so:

void main(){
	while(true){
		int x = 5;
		if(x != 5) continue;
		break;
	}
}


More information about the Digitalmars-d-learn mailing list