Computer Applications
What are loop control structures? What are the essential segments of a loop control structure?
Answer
A loop is a set of instructions that is continually repeated until a certain condition is met. Looping control structures refer to certain looping constructs which execute a block of code repeatedly until a certain condition remains true. For example, for loop, while loop, do - while loop etc.
The essential parts of a looping control structure are as follows:
Initialisation — This segment initialises the loop control variable before starting the loop. It is executed only once at the beginning of the loop.
For example,int counter = 1;Test-condition — The test-condition is the expression that is evaluated at the beginning of each iteration. Its value determines whether the body of the loop is to be executed (test condition is true) or the loop is to be terminated (test condition is false).
For example,counter <= 10Update — This is the increment or decrement operation of the control variable. This operation is performed at the end of each iteration.
For example,counter++;
Related Questions
State whether the following statement is True or False :
An infinite loop can be constructed using a while loop only.
State whether the following statement is True or False :
The statements that facilitate unconditional transfer of control are called jump statements.
How are these statements different from each other?
i. breakii. continue
iii. System.exit(0)
iv. return
Identify all the errors in the following statements.
for (int i = 5; i > 0; i++) { System.out.println("Java is fun!"); }