Smart slicing
    Jesse Phillips 
    jessekphillips at gmail.com
       
    Sun Mar 30 19:27:47 PDT 2008
    
    
  
On Sun, 30 Mar 2008 19:44:57 -0400, bearophile wrote:
> Jesse Phillips:
>> He is not referring to when it is the programmers intent to do it. It
>> is the times when an index has gone out of bounds by accident.
>> while(true) {
>>      writefln(str[i++]);
> 
> I was talking about _slicing_, not about array indexing (that is 1..5
> instead of 5), so you are talking about something different. For a
> single index I agree that's an error (and that's a runtime error in
> Python too).
> 
> In the meantime nearly everyone has said this is a bad feature to add to
> D, so I have stopped advocating for it :-) There are quite more
> important things I like to think/talk about.
> 
> Bye,
> bearophile
ah, yes, my mistake. I forgot that I was reading old articles. In any 
case I will explain what I was aiming for, and I did mean to use slicing.
while(true) {
    auto subStr = str[0..i++];
    //Do stuff with subStr
}
I just wanted to point out that if a variable is used an the programmer 
wishes to stop the said "loop" when you have reached the end but forgot 
to check, you have a working program that false to work as expected.
    
    
More information about the Digitalmars-d
mailing list