Which Windows batch construct is used to repeat commands with a numeric sequence?

Study for the SANS560 GIAC Penetration Tester (GPEN) Test. Study with flashcards and multiple choice questions, each question has hints and explanations. Get ready for your exam!

Multiple Choice

Which Windows batch construct is used to repeat commands with a numeric sequence?

Explanation:
The concept being tested is using a loop construct that is designed for numeric sequences. Windows batch files provide a loop that specifically increments or decrements a counter across a numeric range, making it ideal for repeating commands a set number of times or stepping through values. This construct works by specifying a start value, a step (the amount to add each iteration), and an end value, all inside parentheses after the loop keyword. The general form is: loop variable in (start,step,end) do command. In a batch file, you write the loop variable with double percent signs (%%), for example: for /L %%i in (1,1,10) do echo %%i. This prints numbers from 1 to 10, stepping by 1. If you’re typing directly at the command prompt, you’d use a single percent sign: %i. You can also count down by using a negative step, like (10,-1,1). Why this is the best fit: it’s the only loop form that is explicitly built to handle a numeric sequence and control the progression by a step value. The other constructs don’t provide a built-in numeric sequence loop: a different form of FOR processes text lines or command output, IF handles conditionals, and GOTO simply jumps to a label without providing a structured numeric iteration.

The concept being tested is using a loop construct that is designed for numeric sequences. Windows batch files provide a loop that specifically increments or decrements a counter across a numeric range, making it ideal for repeating commands a set number of times or stepping through values.

This construct works by specifying a start value, a step (the amount to add each iteration), and an end value, all inside parentheses after the loop keyword. The general form is: loop variable in (start,step,end) do command. In a batch file, you write the loop variable with double percent signs (%%), for example: for /L %%i in (1,1,10) do echo %%i. This prints numbers from 1 to 10, stepping by 1. If you’re typing directly at the command prompt, you’d use a single percent sign: %i. You can also count down by using a negative step, like (10,-1,1).

Why this is the best fit: it’s the only loop form that is explicitly built to handle a numeric sequence and control the progression by a step value. The other constructs don’t provide a built-in numeric sequence loop: a different form of FOR processes text lines or command output, IF handles conditionals, and GOTO simply jumps to a label without providing a structured numeric iteration.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy