On 08/28/2014 06:33 PM, Tres Finocchiaro wrote:
>
>     for (int i = 0; i < 1; i += step)
>     This loop will either only iterate once, or it'll get stuck in
>     infinite loop. Pop quiz... can you spot why?
>
>
> If step > 1, it becomes 1 and dies.
> If step < 1, it becomes 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10,
> -11, -12, -13, -14, -15, -16, -17, -18, -19
> If step = 0, it becomes 0, 0 , 0, 0, 0, 0, 0 , 0, 0, 0, 0 , 0, 0,  0,
> 0 , 0, 0,  0, 0 , 0, 0,  0, 0 , 0, 0

Gold star for Tres ;)

In this case, I believe the variable step is a float which is between 0
and 1 (noninclusive), which would mean that the loop would run forever
(since it's rounded to 0 before getting added to the int). It's been
ages since I've touched any C# code so I don't remember if C# has some
implicit conversion weirdness which would allow the loop to function as
intended, but in C/C++ it definitely doesn't work.


------------------------------------------------------------------------------
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
LMMS-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/lmms-devel

Reply via email to