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.

Now answer the exercise about the content:

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

You are right! Congratulations, now go to the next page

You missed! Try again.

Article image repeating loops

Next page of the Free Ebook:

27repeating loops

2 minutes

Obtenez votre certificat pour ce cours gratuitement ! en téléchargeant lapplication Cursa et en lisant lebook qui sy trouve. Disponible sur Google Play ou App Store !

Get it on Google Play Get it on App Store

+ 6.5 million
students

Free and Valid
Certificate with QR Code

48 thousand free
exercises

4.8/5 rating in
app stores

Free courses in
video, audio and text