QAProgramming › A mistake programmers often make with loops is that they ____.
Q

A mistake programmers often make with loops is that they ____.

a. neglect to initialize the loop control variable prior to entering the loop body

b. increment the loop control variable inside of the loop body

c. validate data to ensure values are the correct data type or that they fall within an acceptable range

d. enclose the inner loop entirely within the outer loop in a nested loop

A

Answer: A. Neglect to initialize the loop control variable prior to entering the loop body

Failing to assign initial values (initialization) to the loop control variables (as well as other variables) is a common problem most programmers often make. It is important since the initialization is used at the start of a loop to initialize the loop. Since it is executed at one time in the beginning of a loop, the initialization stage/ step is executed just before the “while” statement of the program.

The programmer must initialize all variables that start with specific values. When a loop appears in another, it is referred to as an indented loop. A loop control variable is important because it provides a starting value for variables that control the loop. Also, it helps test a loop control variable to check if the loop body executes. It also helps alter loop control variables.

3 years ago
355 Views