Welcome to Web-News
A Web-based News Reader
Subject do ... while visibility rules
From h3r3tic <foo@bar.baz>
Date Mon, 25 Oct 2004 10:14:17 +0200
Newsgroups digitalmars.D

It has always seemed counter-intuitive to me that in the <while> block
of the <do...while> loop inner names can't be accessed...
simplest example: bubble sort

do {
     bool changes = false;

     // iterate thru all elements
     // if swapping anything, set changes = true
} while (changes)

^ This will cause an error complaining about undefined identifier
'changes'. Yet it's more intuitive to code that way...


bool changes;
do {
     changes = false;

     //...
} while (changes)

^ This will work fine


It seems a little bit C-ish to explicitly define a variable just two
lines above its initialization. Maybe this could be changed yet ? Or am
I missing something ?

Recent messages in this thread
 
-# do ... while visibility rules (Current message) h3r3tic 25-Oct-2004 04:14 am
.-# Re: do ... while visibility rules Ivan Senji 25-Oct-2004 08:06 am
.|-# Re: do ... while visibility rules h3r3tic 25-Oct-2004 10:11 am
.|.|# Re: do ... while visibility rules JSRS 25-Oct-2004 10:40 pm
.|.\# Re: do ... while visibility rules Ivan Senji 26-Oct-2004 02:47 am
.\# Re: do ... while visibility rules Derek Parnell 25-Oct-2004 11:00 pm