You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
= if (conditional) and ==, !=, <, > (comparison operators)
11
+
= if (condición) and ==, !=, <, > (operadores de comparación)
12
12
13
13
14
14
// OVERVIEW SECTION STARTS
15
15
[#overview]
16
16
--
17
17
[float]
18
-
=== Description
19
-
The `if` statement checks for a condition and executes the proceeding statement or set of statements if the condition is 'true'.
18
+
=== Descripción
19
+
La instrucción `if` verifica si hay una condición y ejecuta la declaración o el conjunto de declaraciones si la condición es `true`.
20
20
[%hardbreaks]
21
21
22
22
[float]
23
-
=== Syntax
23
+
=== Sintaxis
24
24
[source,arduino]
25
25
----
26
-
if (condition)
26
+
if (condición)
27
27
{
28
-
//statement(s)
28
+
//Instrucion(es)
29
29
}
30
30
----
31
31
32
32
[float]
33
-
=== Parameters
34
-
condition: a boolean expression i.e., can be `true` or `false`
33
+
===Parámetros
34
+
condition: una expresión booleana (es decir, puede ser `true` o `false` ).
35
35
36
36
[float]
37
-
=== Example Code
37
+
=== Código de ejemplo
38
38
39
-
The brackets may be omitted after an if statement. If this is done, the next line (defined by the semicolon) becomes the only conditional statement.
39
+
Los corchetes pueden omitirse después de una declaración `if`. Si se hace esto, la siguiente línea (definida por el punto y coma) se convierte en la única instrucción condicional.
The statements being evaluated inside the parentheses require the use of one or more operators shown below.
62
-
[%hardbreaks]
60
+
=== Notas y advertencias
61
+
Las declaraciones que se evalúan dentro de los paréntesis requieren el uso de uno o más operadores que se muestran a continuación.[%hardbreaks]
63
62
64
-
*Comparison Operators:*
63
+
*Operadores de comparación:*
65
64
66
-
x == y (x is equal to y)
67
-
x != y (x is not equal to y)
68
-
x < y (x is less than y)
69
-
x > y (x is greater than y)
70
-
x <= y (x is less than or equal to y)
71
-
x >= y (x is greater than or equal to y)
65
+
x == y (x es igual a y)
66
+
x != y (x no es igual a y)
67
+
x < y (x es menor que y)
68
+
x > y (x es mayor que y)
69
+
x <= y (x es menor o igual que y)
70
+
x >= y (x es mayor o igual que y)
72
71
73
72
74
-
Beware of accidentally using the single equal sign (e.g. `if (x = 10)` ). The single equal sign is the assignment operator, and sets `x` to 10 (puts the value 10 into the variable `x`). Instead use the double equal sign (e.g. `if (x == 10)` ), which is the comparison operator, and tests _whether_ `x` is equal to 10 or not. The latter statement is only true if `x` equals 10, but the former statement will always be true.
73
+
Tenga cuidado de usar accidentalmente el signo igual único (Por ejemplo `if (x = 10)` ). El signo igual único es el operador de asignación y se establece `x` en 10(pone el valor 10 en la variable `x`). En su lugar, utilice el doble signo igual (ejemplo `if (x == 10)` ), Que es el operador de comparación, y comprueba si `x` es igual a 10 o no. El último enunciado solo es verdadero si `x` es igual a 10, pero el enunciado anterior siempre será verdadero.
75
74
76
-
This is because C evaluates the statement `if (x=10)` as follows: 10 is assigned to `x` (remember that the single equal sign is the (http://arduino.cc/en/Reference/Assignment[assignment operator^])), so `x` now contains 10. Then the 'if' conditional evaluates 10, which always evaluates to `TRUE`, since any non-zero number evaluates to TRUE. Consequently, `if (x = 10)` will always evaluate to `TRUE`, which is not the desired result when using an 'if' statement. Additionally, the variable `x` will be set to 10, which is also not a desired action.
75
+
Esto se debe a que C ++ evalúa la sentencia de `if (x=10)` de siguiente manera: se asigna 10 a x(recuerde que el signo igual único es el ( operador de asignación ) (http://arduino.cc/en/Reference/Assignment[assignment operator^]), por lo que ahora `x` contiene 10. Luego, el condiciona 'if' conditional evalúa 10, que siempre se evalúa como `true`, porque un número distinto de cero se evalúa como `true`. En consecuencia, `if (x = 10)` siempre evaluará como `TRUE`, que no es el resultado deseado cuando se utiliza una instrucción `if`. Además, la variable `x` se establecerá en 10, que tampoco es una acción deseada.
0 commit comments