Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to increment my variable value in fastly ?

Status
Not open for further replies.

karthikarun

Newbie level 2
Newbie level 2
Joined
Aug 21, 2015
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
10
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???
}

thanks for advance help.
 
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;
 
Thanks a lot betwixt, xenos for your valued reply.

I'm tried xenos code. its work well.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top