πŸ“’ Too many exams? Don’t know which one suits you best? Book Your Free Expert πŸ‘‰ call Now!

  • google app store apple app store
  • βœ–

      Question

      A program needs to process elements from a `Queue` until

      it becomes empty. Which control flow structure is most suitable for this task?Β 
      A `for` loop with a fixed counter. Correct Answer Incorrect Answer
      B `if-else` statement. Correct Answer Incorrect Answer
      C `while` loop checking if the queue is not empty. Correct Answer Incorrect Answer
      D `switch-case` statement based on the first element. Correct Answer Incorrect Answer

      Solution

      A `while` loop is ideal for processing elements from a queue because the number of elements is dynamic and unknown beforehand. The loop continues as long as the condition (queue not empty) is true.

      Practice Next
      ask-question