control structures

Página 26

Control structures are fundamental in programming, as they allow the programmer to control the flow of execution of the program. These structures are divided into three types: sequence control structures, selection control structures, and repetition control structures.

Sequence control structures

The sequence control structures are the simplest, as they only indicate the order in which the instructions must be executed. That is, the statements are executed one after the other, in the order in which they appear in the code.

Selection control structures

Selection control structures allow the program to execute different statements depending on a condition. The condition is evaluated and, depending on the result, the program chooses which statement to execute.

There are two selection control structures: the if and the switch. The if is used when there are only two options of statements to be executed, while the switch is used when there are more than two options.

Repeating Control Structures

Repeating control structures allow a program to execute a set of statements multiple times as long as a condition is true. There are three loop control structures: the while, the do-while, and the for.

The while is used when you don't know how many times the set of instructions should be executed. do-while is similar to while, but guarantees that the set of statements will be executed at least once. The for is used when you know how many times the set of instructions must be executed.

In summary, control structures are essential for the programmer to be able to control the program's execution flow. Mastering these structures is critical to writing more efficient code with fewer errors.

Ahora responde el ejercicio sobre el contenido:

_What is the control structure used when it is known how many times a set of instructions must be executed?

¡Tienes razón! Felicitaciones, ahora pasa a la página siguiente.

¡Tú error! Inténtalo de nuevo.

Siguiente página del libro electrónico gratuito:

27repeating loops

¡Obtén tu certificado para este curso gratis! descargando la aplicación Cursa y leyendo el libro electrónico allí. ¡Disponible en Google Play o App Store!

Disponible en Google Play Disponible en App Store

+ 6,5 millones
estudiantes

Certificado gratuito y
válido con código QR

48 mil ejercicios
gratis

Calificación de 4.8/5
en tiendas de aplicaciones

Cursos gratuitos de
vídeo, audio y texto.