CompTIA A+ Core 2 (220-1202)Operational ProceduresMedium

A technician is writing a script to process every file in a folder and rename each one according to a naming convention. Which of the following scripting constructs is REQUIRED to repeat the same set of actions for each file automatically?

  1. AAn environment variable
  2. BA loop
  3. CA single variable declaration
  4. DAn inline comment
Show answer & explanation

Correct answer: B. A loop

A loop (such as a ForEach or For loop) allows a script to iterate through each item in a collection, such as files in a folder, and repeat the same actions automatically. Variables store data, comments document code, and environment variables hold system-level settings—none of these provide repetition.

Why the other options are wrong

  • A. Environment variables store system settings, not iteration logic.
  • C. A variable stores a single value but does not repeat actions.
  • D. Comments document code and are ignored during execution.

Scripting Loop

A programming construct that repeats a block of code for each item in a set, such as processing every file in a folder.

  • Common types: For, ForEach, While
  • Essential for batch processing multiple items
  • Different from variables, comments, or environment variables

Memory trick: Loop it to do it again and again.

More Operational Procedures questions