Continue to Site

# How to increment my variable value in fastly ?

Status
Not open for further replies.

#### karthikarun

##### Newbie level 2
maximum value = 1000.
int i;

if(condition_1==true)
{
//variable i should get increment by 1.
}

else if(condition_2==true)
{
//variable i should reach the maximum value 1000 faster . How to write logic for this???
}

Last edited by a moderator:

maximum value = 1000.
int i;
Code:
if(condition_1==true)
{
//variable i should get increment by 1.
[COLOR=#FF0000]i++; // this adds 1 to the value of i[/COLOR]
}

else if(condition_2==true)
{
//variable i should reach the maximum value 1000 faster . How to write logic for this???
[COLOR=#ff0000]i += increment;   //increment is the amount you want it to increase by each time[/COLOR]
}

Set 'increment' to a value before using it or else put the actual value in the line. If the maximum is 1000 and you want it to reach that 1000 times faster you only have one step of increase, you could change the second red line to ' i = 1000'.

Brian.

Supposing you want to use it in a limited keys keyboard routine, you could use something like that (auto adjustable increment):

Code:
        //maximum value = 1000.
//int i;

static unsigned char speed = 1;
if(condition_1==true)
{
//variable i should get increment by 1.
speed = 1;
i++;
} else if(condition_2==true)
{
//variable i should reach the maximum value 1000 faster . How to write logic for this???
if(speed<20)
speed++;
i+=speed;
}
if(i>1000)
i = 1000;

bigdogguru

Points: 2