MOCK TEST

Cards (11)

  • Which loop construct in Java is best suited when the number of iterations is known?
    for loop
  • What is the purpose of the continue statement in a loop?
    • A: To exit the loop immediately
    • B: To skip the current iteration and move to the next iteration
    • C: To terminate the program
    • D: To execute a specific block of code 
    B
  • Which loop construct in Java is best suited when the number of iterations is unknown?
    while loop
  • What is the key difference between a while loop and a do-while loop in Java?
    • A: The syntax used to define the loop
    • B: The number of iterations performed
    • C: The condition check timing
    • D: The ability to use the break statement 
    C
  • Which loop construct guarantees that the loop body is executed at least once? 
    do-while loop
  • What is an infinite loop?
    • A: A loop that executes only once
    • B: A loop that never terminates naturally
    • C: A loop that contains an unreachable code block
    • D: A loop that uses the continue statement
    B
  • Which statement is used to exit a loop prematurely?
    break
  • Which loop construct is best suited for iterating over an array or a collection? 
    for loop
  • Which type of loop is best known for its boolean condition that controls entry to the loop? 
    while
  • Which type of loop is best known for using an index or counter?
    for loop
  • Which of the following can loop through an array without referring to the elements by index?
    • A: do-while loop
    • B. for (traditional)
    • C. for-each
    • D. while
    C - loop through the collection and each time through the loop, it will use the next item from the collection