foreach(ubyte j;0 .. num) is bugging out

jfondren julian.fondren at gmail.com
Thu Sep 23 00:17:49 UTC 2021


On Thursday, 23 September 2021 at 00:06:42 UTC, Ruby The Roobster 
wrote:
> So, I have the following function:
> ```d
> 	        writeln(tempcolor); //For this matter, the program 
> correctly reports tempcolor as 1...
> 		for(ubyte j = 0;j < tempcolor; j++ /*trying ++j has same 
> effect*/ )	{ //tempcolor is 1, yet this sloop gets executed 
> twice...
> 			writeln();
> 			posfunc(ftext, main, exp, temp, i, j, points , x);           
>                              //Orignally foreach loop, but 
> switching to for loop has same effect...
> 		}
> ```

Needs more print in your print debugging:

```d
writeln("tempcolor: ", tempcolor);
...
writeln("in tempcolor with j: ", j);
```

output:

```
tempcolor: 1
in tempcolor with j: 0
...
... numbers
...
tempcolor: 0
tempcolor: 0
tempcolor: 0
tempcolor: 0
tempcolor: 0
tempcolor: 0
tempcolor: 0
tempcolor: 0
tempcolor: 0
tempcolor: 1
in tempcolor with j: 0
...
... numbers
...
```

Here's a oneliner to reproduce to abc.txt:

```
rdmd --eval '"00 00 00 01 00 00 00 00 00 00 00 00 00 01 00 00 00 
00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 01".split(" 
").map!(s => cast(char) s.to!ubyte).write' > abc.txt
```


More information about the Digitalmars-d-learn mailing list