length's type.
kdevel
kdevel at vogtner.de
Thu Feb 8 17:38:39 UTC 2024
On Thursday, 8 February 2024 at 16:54:36 UTC, Kevin Bailey wrote:
> [...]
> On Thursday, 8 February 2024 at 15:26:16 UTC, kdevel wrote:
>>
>> Elegant and correct is this version:
>>
>> ```d
>> import std.stdio;
>>
>> int main()
>> {
>> char[] something = ['a', 'b', 'c'];
>>
>> writeln("len: ", something.length);
>> writeln("typeid(something.length): ",
>> typeid(something.length));
>>
>> writeln ("i: -1");
>> foreach (i, _; something)
>> writeln("i: ", i);
>> return 0;
>> }
>> ```
>>
>> But it is still a bit too "clever" in the `foreach` statement
>> due to the unused variable `_`.
>
> It has a bigger problem. What happens when I change the code in
> the loop but forget to change the code outside the loop?
How exactly is that pseudo index `-1` related to the real indices
of the array `something`? This is absolutely not clear to me. I
simply don't see what problem you are trying to solve.
More information about the Digitalmars-d-learn
mailing list