mirror of
https://github.com/php/doc-es.git
synced 2026-03-24 07:22:16 +01:00
Sync 40 Spanish translation files with latest English source changes: - context/, wrappers/: bump hashes (role attributes already applied) - control-structures/: indentation and typo fixes - oop5/final: indentation restructure, split note blocks - oop5/property-hooks: add missing property declaration in example - oop5/visibility: add PHP 8.5 asymmetric visibility for static properties - operators/precedence: add pipe operator and throw rows - predefined/attributes: add TARGET_CONSTANT for PHP 8.5 - predefined/closure: add getcurrent entity reference - predefined/*: bump hashes (phpdoc entity changes already applied)
88 lines
2.7 KiB
XML
88 lines
2.7 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- EN-Revision: 690c3ea7c7d416c55e2c54d90bfd1f7f4d489288 Maintainer: PhilDaiguille Status: ready -->
|
|
<!-- Reviewed: no -->
|
|
|
|
<sect1 xml:id="control-structures.else" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
<title>else</title>
|
|
<?phpdoc print-version-for="else"?>
|
|
<para>
|
|
A menudo, se desea ejecutar una sentencia si una
|
|
condición se cumple y otra sentencia si esta condición
|
|
no se cumple. Para esto se utiliza <literal>else</literal>.
|
|
<literal>else</literal> funciona después de un
|
|
<literal>if</literal> y ejecuta las sentencias
|
|
correspondientes en caso de que la expresión del <literal>if</literal>
|
|
sea &false;. En el siguiente ejemplo, este fragmento de código
|
|
muestra <computeroutput>a es más grande que b</computeroutput> si la
|
|
variable <varname>$a</varname> es más grande que la variable
|
|
<varname>$b</varname>, y <computeroutput>a es más pequeño que b</computeroutput>
|
|
en caso contrario:
|
|
<informalexample>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
if ($a > $b) {
|
|
echo "a es más grande que b";
|
|
} else {
|
|
echo "a es más pequeño que b";
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</informalexample>
|
|
Las sentencias después del <literal>else</literal> solo se
|
|
ejecutan si la expresión del <literal>if</literal>
|
|
es &false;, y si existen expresiones <literal>elseif</literal>
|
|
- solo si también se evalúan como &false; (ver <link
|
|
linkend="control-structures.elseif">elseif</link>).
|
|
</para>
|
|
<note>
|
|
<title>Dangling else</title>
|
|
<para>
|
|
En el caso de sentencias <literal>if</literal>-<literal>else</literal>
|
|
anidadas, un <literal>else</literal> siempre se asocia con el
|
|
<literal>if</literal> más cercano.
|
|
<informalexample>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$a = false;
|
|
$b = true;
|
|
if ($a)
|
|
if ($b)
|
|
echo "b";
|
|
else
|
|
echo "c";
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</informalexample>
|
|
A pesar de la indentación (que no tiene importancia en PHP), el
|
|
<literal>else</literal> se asocia con el <literal>if ($b)</literal>,
|
|
por lo que este ejemplo no produce ninguna salida.
|
|
Aunque apoyarse en este comportamiento es válido, se recomienda evitarlo utilizando llaves para resolver cualquier posible ambigüedad.
|
|
</para>
|
|
</note>
|
|
</sect1>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|