Re: Why is dynamic array length required here?

2018-10-21 Thread Samir via Digitalmars-d-learn
Stanislav, Ali, Mike -- Thank you all for your thoughtful and helpful replies to my queries. Apologies that it has taken this long to reply to you. I still haven't been able to find time to go through all of the code examples provided but hope to do so later this week. If I have additional

Re: Why is dynamic array length required here?

2018-10-18 Thread Mike Parker via Digitalmars-d-learn
On Friday, 19 October 2018 at 02:04:37 UTC, Samir wrote: I would have thought that since this is a dynamic array, I don't need to pre-assign its length. Thanks Just to expand on the previous answers, a dynamic array declaration with no initializer is an empty array: int[] arr;

Re: Why is dynamic array length required here?

2018-10-18 Thread Ali Çehreli via Digitalmars-d-learn
On 10/18/2018 07:04 PM, Samir wrote: > myArray.length = noValues; // I get a run-time error if I comment > this out It's because the expression that reads the elements below is readf, which reads on top of an existing element. > while (i < noValues) { > write("enter value

Re: Why is dynamic array length required here?

2018-10-18 Thread Stanislav Blinov via Digitalmars-d-learn
On Friday, 19 October 2018 at 02:04:37 UTC, Samir wrote: I am working my way through the exercises in the "Programming in D" tutorial (http://ddili.org/ders/d.en/arrays.html). Why is the line assigning the length of the dynamic array required? [...] Without the line: myArray.length =

Why is dynamic array length required here?

2018-10-18 Thread Samir via Digitalmars-d-learn
I am working my way through the exercises in the "Programming in D" tutorial (http://ddili.org/ders/d.en/arrays.html). Why is the line assigning the length of the dynamic array required? /* Write a program that asks the user how many values will be entered and then reads all of them. Have