Loops in C++

Опубликовано: 06 Октябрь 2024
на канале: King of Techniques
40
2

#loops #nestedloops #loopsinprogramming

@King

Loops are among the most basic and powerful programming concepts. A loop in a computer program is an instruction that repeats until a specified condition is reached. In a loop structure, the loop asks a question. If the answer requires action, it is executed. The same question is asked again and again until no further action is required.

Loop is an entry-controlled loop, meaning that the condition specified by us is verified before entering the loop block. It is a repetition control structure. The loop written by us is run a specified number of times. To control the loop, we use a loop variable in For loop.

A loop in C consists of two parts, the body of a loop and a control statement. The control statement is a combination of some conditions that direct the body of the loop to execute until the specified condition becomes false.

Types of Loops in C++

1- For Loop. Loop is an entry-controlled loop, meaning that the condition specified by us is verified before entering the...
2 - While Loop. While loop is also an entry-controlled loop, where we verify the condition specified by us, before running...
3- Do while loop is an exit-controlled loop, meaning the test condition is verified after the execution of the loop, at the end of the body of the loop. Hence, the body executes at least once, regardless of the result of the test condition, whether it is true or false. This happens to be the foremost difference between while loop and do while. In while loop, the condition is tested beforehand, whereas in do while loop the condition is verified at the finish of body of the loop.