PROCEDURE drawSquare(size):  FOR side FROM 1 TO 4:     forward(size)     turnLeft(90)This code uses:SelectionIterationSequencing

1 answer

The code you've provided for the procedure drawSquare(size) primarily uses iteration.

Here's why:

  • Iteration: The FOR loop iterates four times (from 1 to 4) to draw the four sides of the square. This is a classic example of using a loop to repeat a block of code.

  • Sequencing: This is also present in the sense that the actions within the loop (the forward(size) and turnLeft(90)) are executed in a specific order during each iteration. However, sequencing itself is a fundamental concept that is present in most programming constructs.

  • Selection: This does not appear in the provided code. Selection usually involves conditional statements (like if or switch), which determine which paths of execution to take based on certain conditions.

In summary, the primary control structure demonstrated in your procedure is iteration.