A type of control structure that repeats a statements is known as looping structure. It is also known as iterative or repetitive structure. In sequential structure all statements are executed once.on the other hand Conditional structure may execute or skip a statement on the basis of some given condition.In some situations it is required to repeat s statement or number of statements For a Special number
of Times. Looping Structures are used for this purpose. There are different types of loops available in
C++.
Counter Controlled Loops
This type of loop depends on the value of a variable known as counter variable. The value
of counter variable is incremented or decremented each time the body of the loop is executed
. So This Loop terminates when the value of counter variable reaches a particular value. The
Number of iterations of counter controlled loop is in advance.The iteration of this loop depends on the terminating condition,increment or decrement value.
Sentinel Controlled Loops
This type of loop depends on special value known as sentinel value. The Loop terminates
when the sentinel value is encountered. These Types of loops are also known as conditional
loops. A Loop may execute while the value of a variable is not here. The Number of iteration
of sentinel controlled loop is unknown. It depends on the input from the users. Suppose the
sentinel value to terminates a loop is 1 if the users enter 1 in first iteration,the loop will
execute only once. But if the user enter after entering many other values,the number of iterations
will very accordingly. A sentinel value is commonly used with while and Do-while loop.
While Loop
This is the simplest loop of C++ language. This Loop executes one or more statements while the
given condition remains true. It is useful when the number of iterations is not known in advance.First of All the condition is evaluated. If it is true,the control enters the body of the loop and executes
all statements in the body. After executing the statements it again moves to the start of the loop
and evaluates the condition again. This process continues as long as the condition remains true.
When the condition becomes false/the conditions remains true,the loop never ends. A loop that
has not end points is known as an infinite loop.
Tweet
Share this post to
Comments From Facebook











0 comments:
Post a Comment