COMPTIA-SK0-005 practice question 29 of 35
Which of the following should a server administrator use when writing a script with a function that needs to be run ten times?
Full set: 493 questionsA loop is a control flow statement used in scripting and programming to execute a block of code repeatedly. To perform an action a specific number of times, such as running a function ten times, a for loop is the ideal construct. The administrator can define the loop to iterate from one to ten, calling the function within the loop's body on each iteration. This automates the repetitive task efficiently and is a fundamental concept in scripting for server administration.
B. Variable: A variable is a named storage location for data; it does not, by itself, cause code to be executed repeatedly.
C. Comparator: A comparator (e.g., ==, >, <) is an operator used to compare two values, typically within a conditional or loop, but it is not the structure that performs the repetition.
D. Conditional: A conditional statement (e.g., if-else) executes a block of code based on whether a condition is true or false; it does not inherently repeat the execution. ---
1. Guttag, J. V. (2016). Lecture 2: Branching and Iteration. MIT OpenCourseWare, 6.0001 Introduction to Computer Science and Programming in Python. Retrieved from https://ocw.mit.edu/courses/6-0001-introduction-to-computer-science-and-programming-in-python-fall-2016/resources/lecture-2-branching-and-iteration/. The lecture notes explicitly define iteration (loops) as a mechanism for repeated execution of a block of code.
2. Microsoft. (2023, November 13). aboutFor - PowerShell. Microsoft Learn. Retrieved from https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/aboutfor. The documentation states, "The For statement (also known as a For loop) is a language construct you can use to create a loop that runs commands in a command block while a specified condition evaluates to $true."
3. Free Software Foundation. (2022, December 29). Bash Reference Manual. Section 3.2.4.1 Looping Constructs. Retrieved from https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Looping-Constructs. This section describes the for loop, which is used to "execute a sequence of commands for each member in a list of items."
Keep practicing
Take the free COMPTIA-SK0-005 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other COMPTIA-SK0-005 practice questions
- Question 1A server that recently received hardware upgrades has begun to experience random BSOD con…
- Question 2A technician is installing a large number of servers in a data center with limited rack s…
- Question 3A server administrator recently installed a kernel update to test functionality Upon rebo…
- Question 4A company stores extremely sensitive data on an alt-gapped system. Which of the following…
- Question 5Winch of the following is a type of replication in which all files are replicated, all th…
- Question 6A server technician is installing a new server OS on legacy server hardware. Which of the…
