Dynamic array and foreach loop
Jay Norwood via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Aug 8 17:22:52 PDT 2015
On Saturday, 8 August 2015 at 18:28:25 UTC, Binarydepth wrote:
>> This is the new code :
>>
>> foreach(num; 0..liEle) {//Data input loop
>>
>> write("Input the element : ", num+1, " ");
>> readf(" %d", &liaOrig[num]);
>> }
>
> Even better :
>
> foreach(num; 0..liaOrig.length
I believe they usually do something like:
foreach( num, ref elem; liaOrig){
}
which creates the index num and the reference to the element of
range liaOrig.
It also seems that a lot of discussion is going on about reducing
use of foreach loops in their preferred style, so you might want
to try some of that.
More information about the Digitalmars-d-learn
mailing list