DEV Community

Milena
Milena

Posted on

Control structures

Lets talk about the advantages and disadvantages of each looping structure...

I could be wrong, but I wouldn't use the word "disadvantage" in concepts like loops. We have different types because they can all work in different cases, but sometimes they are not suitable for it. So it is important to have a lot of knowledge of this concept because it makes it easier for us to understand, simplifies the code, and becomes a more fluid program.

Now, citing advantages of loops:

while: will repeat the proposed block of code, until the condition is true

do-while: will do something while a condition is true. I see people calling it a "control repeat structure"

for: already in this loop, we have a repetition structure with iteration, where we iterate a defined value in each repetition, reaching a limit.

I confess that I always get confused with repeat structures and, sometimes, with conditionals. But they are very important concepts, as I mentioned before.

What are your thoughts?

Top comments (0)