How to loop and increase by 0.01 each time?

I am really confused in this code.

Here is what I want to do: Start with a value of "v" 5, do the rest of the functions / calculations, increase the value of "v" by 0.01, perform the functions / calculations, then increase the "v" value by 0.01 again, execute the functions. .. do this 500 times or until the value "v" reaches 10.00, whichever is easier to code.

Here is my code at the moment:

//start loop over v  
for(iv=5;iv<=500;iv++) {  
    v=0.01*iv;
    //Lots and lots of calculations with v here
}

Here's what I get: I tried setting iv <= 10, so it only does 10 cycles so that I can check it first before leaving it all night. He performed only 6 cycles, starting with v = 0.05 and ending with 0.1. Thus, the problem is that a) it did not start for 10 cycles, b) it did not start at 5.00, it started at 0.05.

Any help would be greatly appreciated.

EDIT: Holy crap, so many answers! I already tried 2 different answers, both work! I looked at it and changed the code for 3 hours, I can’t believe that it was that simple.

+3
source share
6 answers

You need to start with iv = 500. and if you want 10 cycles, and iv++this is an update, you stop before 510.

: v = 0.01*iv, v = 5 iv = 5/0.01 = 500. , for for (x = N; x < M; x++) ( N M), max(0, M-N), x (, , ..).

v = 0.01 * iv, v = iv / 100.0, , . : 0.01 , 100.0.

+7

SiegeX, ( " " ):

double dv;
int iv;
for(iv = 500; dv <= 1000; iv += 1)
{
    dv = (double)iv / 100.0;
}
+2
double iv;
for(iv = 5.0; iv <= 10.0 ; iv += 0.01) {
/* stuff here */
}
0
int i;
double v;
v = 5;
for (i = 0; i < 500; i++)
{
    v += 0.01;
    // Do Calculations Here.

    if (v >= 10.00) break;
}

. 500 , , v ( ) 10.00.

:

10.00:

double v;
v = 5.0;
while ( v < 10.00 )
{
    v += 0.01;
    // Do Calculations Here. 
}

500 :

double v;
int i;
v = 5.0;
for( i = 0; i < 500; i++ )
{
    v += 0.01;
    // Do Calculations.
}

( , C99, ).

0

iv <= 10does not do this for 10 cycles, it does so until ivmore than 10.

-1
source
//start loop over v  
for(iv=0;iv<500;iv++) //loop from 0 to 499
{  
    v=v+0.01; //increase v by 0.01
    //Lots and lots of calculations with v here
}

it should do it

-1
source

Source: https://habr.com/ru/post/1778039/


All Articles