C Decision Making and Loops MCQ Questions and Answers
Q. What is the type of loop that is used when the number of iterations is unknown and continues until a certain condition is met?
A. for loopB. while loop
C. do-while loop
D. none of the above
Q. Which loop is used when you want to iterate through a range of values and know the number of iterations beforehand?
A. for loopB. while loop
C. do-while loop
D. none of the above
Q. How can you exit a loop prematurely if a certain condition is met?
A. using the continue statementB. using the break statement
C. using the return statement
D. using the exit statement
Q. What is the purpose of the switch statement in C?
A. to perform arithmetic operationsB. to make decisions based on multiple choices
C. to repeat a block of code
D. to execute a block of code based on different cases
Q. What is the default case in a switch statement used for?
A. to handle arithmetic operationsB. to handle invalid input
C. to handle floating-point numbers
D. to execute code when no other case matches
Q. What is the purpose of the break statement in a switch case?
A. to exit the switch statementB. to continue to the next case
C. to repeat the current case
D. to exit the current case and move to the next statement
Q. What is the purpose of the continue statement in a loop?
A. to exit the loopB. to skip the rest of the current iteration and move to the next iteration
C. to repeat the current iteration
D. to start a new loop
Q. What is the purpose of the Predicate functional interface in Java 8?
A. To produce resultsB. To consume values
C. To filter elements based on a condition
D. To transform values