#1
What is the primary purpose of using control structures in programming?
To control the flow of execution
ExplanationControl structures manage the sequence of code execution.
#2
Which loop in programming executes the code block a specified number of times?
for loop
ExplanationThe 'for' loop iterates over a range, executing code a predetermined number of times.
#3
What does the term 'iteration' mean in the context of loops?
The process of executing a loop repeatedly
ExplanationIteration is the repetitive execution of a loop.
#4
In a 'while' loop, under what condition does the loop continue to execute?
While the condition evaluates to true
Explanation'while' loop continues executing as long as the specified condition remains true.
#5
What is the purpose of the 'for' loop in programming?
To execute a block of code a specified number of times
Explanation'for' loop is used for precise iteration, executing code a set number of times.
#6
Which of the following is NOT a valid loop control statement in programming?
exit
Explanation'exit' is not a standard loop control statement in programming.
#7
What is an infinite loop?
A loop that never terminates
ExplanationAn infinite loop continues endlessly without termination.
#8
What is a pretest loop?
A loop where the condition is checked before each iteration
ExplanationA pretest loop evaluates the condition before each iteration.
#9
Which loop structure is best suited for situations where the number of iterations is not known in advance?
while loop
Explanation'while' loop is suitable for situations with an unknown number of iterations.
#10
What does the 'break' statement do in a loop?
It exits the loop immediately
Explanation'break' terminates the loop prematurely, skipping subsequent iterations.
#11
What is a nested loop?
A loop that is defined within another loop
ExplanationA nested loop is a loop inside another loop, allowing for complex iteration.
#12
What is the difference between 'while' and 'do-while' loops?
'do-while' always executes at least once
Explanation'do-while' ensures the code block is executed once before checking the loop condition.
#13
What is the purpose of the 'switch' statement in programming?
To perform different actions based on different conditions
Explanation'switch' directs program flow based on the value of an expression.
#14
What does the 'else' statement do in an 'if-else' construct?
It executes only if the condition of the 'if' statement is false
Explanation'else' block executes when the 'if' condition is false.
#15
What is the purpose of the 'goto' statement?
To transfer control to a specified label within the same function
Explanation'goto' directs program control to a labeled point in the same function.
#16
What does the 'else if' statement allow for in programming?
To create nested conditions
Explanation'else if' introduces additional conditions within an 'if-else' construct.
#17
What is the purpose of the 'try', 'catch', and 'finally' blocks in exception handling?
To handle errors and exceptions gracefully
Explanation'try', 'catch', and 'finally' blocks manage exception handling, allowing graceful error handling.
#18
What does the term 'loop control variable' refer to?
A variable used to control the number of iterations in a loop
ExplanationA loop control variable manages the number of loop iterations.
#19
What is the purpose of the 'continue' statement in a loop?
To repeat the current iteration of the loop
Explanation'continue' skips the current iteration and proceeds with the next one.
#20
What is a 'control structure' in programming?
A statement that changes the control flow of a program
ExplanationControl structures alter the order in which program statements are executed.
#21
What is the difference between 'break' and 'continue' statements in a loop?
'break' exits the loop entirely, while 'continue' skips the current iteration and continues with the next one
Explanation'break' terminates the loop, while 'continue' skips the current iteration.
#22
In switch statements, what is the purpose of the 'default' case?
To execute if none of the other cases match
Explanation'default' case executes when none of the other switch cases match.
#23
What is an advantage of using a 'for' loop over a 'while' loop?
'for' loops can easily express looping over a range
Explanation'for' loops are concise for iterating over a specified range of values.