info@jobexams.pk

MCQ Detailed View

Explore the question in detail with explanation, related questions, and community discussions.

1 PROGRAMMING MCQS

What is the purpose of a loop in programming?

  • To store data
  • To design the program
  • To repeat a set of instructions
  • None of these
Correct Answer: C. To repeat a set of instructions

Detailed Explanation

In programming, a loop is used to execute a block of code multiple times until a certain condition is met. This helps reduce repetition in the code and makes programs more efficient and easier to manage.


There are different types of loops such as for loops, while loops, and do-while loops. All of them serve the same basic purpose: they allow the same set of instructions to be executed repeatedly. For example, if you want to display a message five times or process a list of items one by one, a loop is the best tool to use.


Using loops avoids writing the same code multiple times and makes the program shorter, cleaner, and easier to update. The loop continues to run until the specified condition becomes false. Once the condition is no longer true, the loop stops, and the program moves on to the next part of the code.

Discussion

Thank you for your comment! Our admin will review it soon.
No comments yet. Be the first to comment!

Leave a Comment