Break/Continue Structure

Rory Starkweather starkweatherr at mchsi.com
Fri Mar 24 02:28:54 PST 2006


Oskar Linde wrote:
> Derek Parnell wrote:
> 
> 
>>BTW, using the foreach this way can be misleading. The pointer value
>>returned represents the number of dchars examined and *not* an index into
>>theString. This is significant if theString is not a dchar[].
> 
> 
> That is not correct. The index returned is an index into the char[] array,
> not the number of dchars processed:
> 
> void main() {
>         foreach(uint ix, dchar c; "åäö"c)
>                 writefln("c = %s, ix = %s",c,ix);
> }
> 
> Prints:
> 
> c = å, ix = 0
> c = ä, ix = 2
> c = ö, ix = 4
> 
> /Oskar


  I'm having some trouble understanding this implementation of the 
'foreach' construct. From the definiton of the'foreach' expression, the 
purpose of the 'c' in . . .; "åäö"c) is not clear to me. Does this 
implicitly declare an array of items with the same data type as 'c'? In 
other words, three dchars in this case? From Oskar's comment that seems 
unlikely.

  For me a large part of the problem is the variable naming convention 
in the documentation, which seems a little ambiguous, although reading 
the entries carefully usually clarifies things. I think I am just not 
used to one letter variable names yet. A style I have never been 
comfortable with. Oddly enough, I am also trying to learn Oberon-2 now, 
and Wirth uses the same convention.



More information about the Digitalmars-d-learn mailing list