easyMultiple ChoiceObjective-mapped
220-1202 Practice Question: A technician is writing a batch script to…
A technician is writing a batch script to automate the installation of a software package on multiple Windows workstations. The script needs to check if the software is already installed before attempting installation. Which scripting construct should the technician use?
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
An if statement
This tests knowledge of conditional logic in scripting. An 'if' statement allows the script to check a condition (e.g., existence of a registry key or file) and execute code only if the condition is true or false. Loops are for repetition, and variables store data, not control flow.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
A for loop
Why it's wrong here
A `for` loop in a batch script is primarily designed for iterating over a predefined set of items, such as files in a directory, lines in a file, or a sequence of numbers. Its purpose is to execute a block of commands repeatedly for each item in that set, not to make a singular, conditional decision about whether to perform an action based on a specific system state or condition. Therefore, it is unsuitable for a one-time check before an installation.
- ✓
An if statement
Why this is correct
An `if` statement is the fundamental control structure used to execute commands conditionally based on the evaluation of a specified condition. It checks whether a given condition, such as the existence of a file or the value of a variable, is true or false. If the condition evaluates to true, the associated block of commands is executed exactly once, making it ideal for checking prerequisites like an existing installation before proceeding with a new action.
- ✗
A variable
Why it's wrong here
While a variable can store data, including the result of a condition check (e.g., `SET file_exists=1`), it does not inherently control the flow of a script or perform conditional logic on its own. A variable merely holds a value; a separate control flow statement, such as an `if` statement, is still required to evaluate the variable's content and then decide whether to execute a particular command or block of code. Therefore, a variable alone cannot automate a conditional decision.
- ✗
A while loop
Why it's wrong here
A `while` loop is designed for continuous execution of a block of commands as long as a specified condition remains true. Its primary function is to repeat actions iteratively until a certain state is achieved or a condition becomes false, implying an ongoing process rather than a single decision point. For a scenario requiring a one-time check of a condition before performing an action, a `while` loop is an inefficient and inappropriate construct, as it implies unnecessary repetition or polling.
Go deeper
Related to this question
About these practice questions
This 220-1202 question is part of Courseiva's 495-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This 220-1202 practice question is part of Courseiva's free CompTIA certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 220-1202 exam.