Practice Test 2 (scored 66 out of 66) new
update Western Governors University
1. Describe how a sentinel value functions within a loop structure.
A sentinel value is a comment that explains the purpose
of a loop. A sentinel value is a type of variable that
stores loop conditions.
A sentinel value is used to indicate when the
loop should terminate, allowing for controlled
exit from the loop.
A sentinel value is a marker for the beginning of a loop.
2. What type of loop is specifically designed for a predetermined
number of iterations?
While
loop
Switch case
Do/while loop
For loop
3. Describe the significance of calling a function after
defining it in programming.
Functions can be executed without being called if they
are defined in the main program.
Functions only need to be defined to be considered part of
the program.
Calling a function is necessary for executing the code
within it, as defining alone does not trigger its
execution.
,Defining a function automatically runs its code without
needing to call it.
,4. Describe the primary difference between an if-else branch
and a while loop in programming.
An if-else branch executes code based on a
condition, while a while loop continues to execute as
long as a condition remains true.
An if-else branch requires a boolean expression, while a
while loop does not.
An if-else branch is used for iteration, while a while loop
is used for decision-making.
An if-else branch can run multiple times, while a while
loop runs only once.
5. What happens when a function is called?
All of the above.
The function is deleted.
Program execution jumps to the function definition and
executes the code in the function body.
The function is defined.
6. What is the primary purpose of an if-else statement in
programming?
To handle
exceptions To
create loops
To check a condition and run one of two code blocks
To define variables
7. Which type of loop checks its condition before executing the loop
body?
while loop
, foreach loop