Reference.Increment History

June 01, 2010, at 12:48 AM by Equipo Traduccion -
Changed lines 20-21 from:

to:

Devuelve

June 01, 2010, at 12:00 AM by Equipo Traduccion - traducciion al espa~ol
Changed lines 1-8 from:

++ (increment) / -- (decrement)

Description

Increment or decrement a variable

to:

++ (incremento) / -- (disminución)

Descripción

Incrementa o disminuye una variable

Sintaxis

Changed lines 10-25 from:

x++; // increment x by one and returns the old value of x ++x; // increment x by one and returns the new value of x

x-- ; // decrement x by one and returns the old value of x --x ; // decrement x by one and returns the new value of x @]

Parameters

x: an integer or long (possibly unsigned)

Returns

The original or newly incremented / decremented value of the variable.

Examples

to:

x++; // incrementa x en uno y regresa el valor anterior de x ++x; // incrementa x en uno y regresa el nuevo valor de x

x-- ; // disminuye x en uno y y regresa el valor anterior de x --x ; // disminuye n uno y regresa el nuevo valor de x @]

Parámetros

x: un entero o long (puede aceptar sin signo)

Regresa

El valor original o el resultante del incremento o disminución de la variable.

Ejemplos

Changed lines 27-31 from:

y = ++x; // x now contains 3, y contains 3 y = x--; // x contains 2 again, y still contains 3 @]

to:

y = ++x; // x ahora guarda 3, y guarda 3 y = x--; // x guarda 2 de nuevo, y sigue guardando 3 @]

Vea también

July 16, 2007, at 04:35 PM by David A. Mellis -
July 16, 2007, at 04:35 PM by David A. Mellis -
Changed line 13 from:

x-- ; // decrement x by one and returns the old value of x @]

to:

x-- ; // decrement x by one and returns the old value of x

July 16, 2007, at 04:35 PM by David A. Mellis - clarifying x++ and ++x, etc.
Changed lines 10-12 from:

x++ ; // equivalent to the expression x = x + 1; x-- ; // equivalent to the expression x = x - 1; @]

to:

x++; // increment x by one and returns the old value of x ++x; // increment x by one and returns the new value of x

x-- ; // decrement x by one and returns the old value of x @] --x ; // decrement x by one and returns the new value of x @]

Changed lines 18-19 from:

x: any variable type

to:

x: an integer or long (possibly unsigned)

Changed lines 22-23 from:

Incremented or decremented variable

to:

The original or newly incremented / decremented value of the variable.

Changed lines 27-30 from:

x++; // x now contains 3 x--; // x contains 2 again@]

to:

y = ++x; // x now contains 3, y contains 3 y = x--; // x contains 2 again, y still contains 3 @]

Deleted lines 31-32:
Deleted line 33:
July 16, 2007, at 12:18 PM by Paul Badger -
July 16, 2007, at 12:17 PM by Paul Badger -
Changed line 23 from:

[@x = 2; // x now contains 2

to:

[@x = 2;

July 16, 2007, at 12:17 PM by Paul Badger -
Changed lines 24-27 from:

x++; // x now contains 3 x--; // x contains 2 again@]

to:

x++; // x now contains 3 x--; // x contains 2 again@]

July 16, 2007, at 12:16 PM by Paul Badger -
July 16, 2007, at 12:16 PM by Paul Badger -
Deleted lines 4-7:

The ++ operator is

The -- operator is equivalent to the expression x = x - 1;

July 16, 2007, at 12:14 PM by Paul Badger -
Changed lines 3-4 from:
to:

Description

July 16, 2007, at 12:14 PM by Paul Badger -
Changed line 35 from:
to:

+=\\

July 16, 2007, at 12:13 PM by Paul Badger -
Changed lines 35-36 from:
to:
July 16, 2007, at 12:08 PM by Paul Badger -
Deleted lines 26-28:

Deleted lines 31-63:

Example Code

```// check a sensor every 10 times through a loop
void loop(){
i++;
if ((i % 10) == 0){          // read sensor every ten times through loop
}
/ ...
}

// setup a buffer that averages the last five samples of a sensor

int senVal[5];  // create an array for sensor data
int i, j;       // counter variables
long average;   // variable to store average
...

void loop(){
// input sensor data into oldest memory slot
average = 0;
for (j=0; j<5; j++){
average += sensVal[j];   // add up the samples
}
average = average / 5;  // divide by total

```

Tip

the modulo operator will not work on floats

July 16, 2007, at 12:07 PM by Paul Badger -

[@

Changed lines 15-17 from:

x-- ; // equivalent to the expression x = x - 1;

to:

x-- ; // equivalent to the expression x = x - 1; @]

July 16, 2007, at 12:06 PM by Paul Badger -
July 16, 2007, at 12:06 PM by Paul Badger -
Changed lines 1-8 from:

++ (increment)

Increment a variable

x++;

to:

++ (increment) / -- (decrement)

Description

The ++ operator is

The -- operator is equivalent to the expression x = x - 1;

Increment or decrement a variable

Syntax

x++ ; // equivalent to the expression x = x + 1; x-- ; // equivalent to the expression x = x - 1;

Parameters

x: any variable type

Returns

Incremented or decremented variable

Examples

```x = 2;    // x now contains 2
x++;        // x now contains 3
x--;        // x contains 2 again
```

Example Code

```// check a sensor every 10 times through a loop
void loop(){
i++;
if ((i % 10) == 0){          // read sensor every ten times through loop
}
/ ...
}

// setup a buffer that averages the last five samples of a sensor

int senVal[5];  // create an array for sensor data
int i, j;       // counter variables
long average;   // variable to store average
...

void loop(){
// input sensor data into oldest memory slot
average = 0;
for (j=0; j<5; j++){
average += sensVal[j];   // add up the samples
}
average = average / 5;  // divide by total

```

Tip

the modulo operator will not work on floats