Click here to Skip to main content
15,745,750 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
if i get what i need the rerun a should be inside of the loop But when i wrote that showed bug .

What I have tried:

float moveValue( float b = 0.0f)

float a =0.0f;

for (float i = 0.0001f; i < 5; i++)

a =i;


return a;
Updated 11-Mar-18 0:04am
Patrice T 11-Mar-18 3:48am    
"But when i wrote that showed bug"
What error message? where? what problem?

what did you try to do with this code?
OriginalGriff 11-Mar-18 4:45am    
You can - it adds 1.0f to it.
Richard MacCutchan 11-Mar-18 9:30am    
Yes, I actually tried it after posting that comment.
OriginalGriff 11-Mar-18 4:47am    
That doesn't make a whole lot of sense - what bug?
If I run that code it does exactly what I expect, and returns 4.0001 - so what is it doing that you didn't expect, or not doing that you did?
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Use the "Improve question" widget to edit your question and provide better information.

1 solution

It looks like you're assuming that the increment will be the same value you're starting our with, and that's not the case. As Griff already pointed out, the increment will always be 1 (0r 1.0 in your case).

If you want to use anything other than an integer increment, you have to use a do/while loop. Also, since you're working with a floating point value, you should call Math.Round if you want the loop to stop at precisely 5.0.

double i = 0d;
    i = Math.Round(i+0.00001d, 5);

    // do something with the new value

} while (i < 5.0d);

If this isn't what you're trying to do, improve your question so someone can provide you with the answer you need.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900