0% found this document useful (0 votes)
14 views21 pages

Estructuras de Control

The document provides an overview of functions and control structures in programming, explaining how to declare and invoke functions, as well as the syntax involved. It details various control statements such as 'break', 'continue', 'for', 'if...else', 'switch...case', 'while', and 'do...while', describing their purposes and usage. The author emphasizes naming conventions for functions and the importance of returning values in functions.

Uploaded by

siregalado
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views21 pages

Estructuras de Control

The document provides an overview of functions and control structures in programming, explaining how to declare and invoke functions, as well as the syntax involved. It details various control statements such as 'break', 'continue', 'for', 'if...else', 'switch...case', 'while', and 'do...while', describing their purposes and usage. The author emphasizes naming conventions for functions and the importance of returning values in functions.

Uploaded by

siregalado
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

FUNCIONES Y ESTRUCTURAS

DE CONTROL
ING. SERGIO IVÁN REGALADO
SALGUERO
Una función es un bloque de
código que tiene un nombre y
un conjunto de instrucciones
que son ejecutadas cuando
ésta es invocada.
LAS FUNCIONES SE DECLARAN ASOCIADAS A UN TIPO DE
VALOR. ESTE VALOR SERÁ EL QUE DEVOLVERÁ LA FUNCIÓN,
POR EJEMPLO ‘INT’ SE UTILIZARÁ CUANDO LA FUNCIÓN
TIPO ENTERO.
DEVUELVA SI NUMÉRICO
UN DATO LA FUNCIÓN
DE DEVUELVE NINGÚN
NO ENTONCES SE COLOCARÁ VALOR LA PALABRA
DELANTE SIGNIFICA “FUNCIÓN “VOID”, QUE
VACÍA”
SINTAXIS

Sintaxis:
tipo nombreFunción
(parámetros) { instrucciones;
}
LLAMAR A UNA FUCIÓN

Para llamar a una función, simplemente:


nombreFunción(parámetros);

En una función que devuelve un valor siempre debe tener la


instrucción Return, este termina una función y devuelve un valor a
quien ha llamado a la función.
NOMBRES DE FUNCIONES

Generalmente los nombres de las funciones deben ser en


minúscula, con las palabras separadas por un guion bajo,
aplicándose éstos tanto como sea necesario para mejorar la
legibilidad.

“mixedCase” (primera palabra en minúscula) es aceptado


únicamente en contextos en donde éste es el estilo
predominante con el objetivo de mantener la compatibilidad
con versiones anteriores.
break
break is used to exit from a for, while or do…while loop, bypassing the
normal loop condition. It is also used to exit from a switch case
statement.
continue
The continue statement skips the rest of the current iteration of a loop
(for, while, or do…while). It continues by checking the conditional
expression of the loop, and proceeding with any subsequent
iterations.
for
The for statement is used to repeat a block of statements enclosed in
curly braces. An increment counter is usually used to increment and
terminate the loop. The for statement is useful for any repetitive
operation, and is often used in combination with arrays to operate on
collections of data/pins.
for
The for statement is used to repeat a block of statements enclosed in
curly braces. An increment counter is usually used to increment and
terminate the loop. The for statement is useful for any repetitive
operation, and is often used in combination with arrays to operate on
collections of data/pins.
got
oto a labeled point in the
Transfers program flow
program
if...else
The if statement checks for a condition and executes the
proceeding statement or set of statements if the
condition is 'true'.
if...else
The if statement checks for a condition and executes the
proceeding statement or set of statements if the
condition is 'true'.
if...else
The if statement checks for a condition and executes the
proceeding statement or set of statements if the
condition is 'true'.
els
e
An else clause (if at all exists) will be executed if the condition in
the if statement results in false. The else can proceed another if
test, so that multiple, mutually exclusive tests can be run at the
same time.
switch...case
Like if statements, switch case controls the flow of programs by allowing
programmers to specify different code that should be executed in
various conditions. In particular, a switch statement compares the value
of a variable to the values specified in case statements.
while
A while loop will loop continuously, and infinitely, until the expression
inside the parenthesis, () becomes false. Something must change the
tested variable, or the while loop will never exit. This could be in your
code, such as an incremented variable, or an external condition, such as
testing a sensor.
do...whil
e
The do…while loop works in the same manner as the while loop, with
the exception that the condition is tested at the end of the loop, so
the do loop will always run at least once.
GRACIAS

Sergio Iván Regalado


Salguero
Arquitectura de
Computadoras 1

You might also like