Class 10 Computer Science Unit 4 – Data and Repetition is one of the most important chapters in programming. In this unit, students learn how data is stored in programs and how repetition structures (loops) help execute tasks multiple times efficiently. Topics like data types, arrays, for loop, while loop, and do-while loop are explained with clear examples.
These notes are specially prepared according to the 10th class board syllabus and include solved MCQs, short questions, long questions, and programming examples for better understanding. Whether you are preparing for board exams or class tests, these notes will help you understand concepts easily and score high marks.
Important MCQs – Unit 4 Data and Repetition
1. An array is a ______ structure.
a) Loop
b) Control
c) Data ✅
d) Conditional
2. ______ structure allows repetition of a set of instructions.
a) Loop ✅
b) Conditional
c) Control
d) Data
3. The first element of an array has index number:
a) 1
b) -1
c) 0 ✅
d) N-1
4. Which of the following is NOT a loop in C language?
a) For loop
b) While loop
c) Switch loop ✅
d) Do-while loop
5. Which statement is true about loops and arrays?
a) Loops cannot access arrays
b) Arrays can replace loops
c) Loops can read/write array values easily ✅
d) Loops can only store integers in arrays
Short Questions – Unit 4 Data and Repetition
1. What is a data structure?
Answer:
A data structure is a special way of organizing and storing a collection of data items in a computer so that they can be accessed and used efficiently. It acts as a container that arranges data in a specific layout to make operations like searching, inserting, and deleting easier.
Data structures help programmers manage large amounts of data in an organized manner. Examples include arrays, structures, and linked lists.
2. Define an array.
Answer:
An array is a data structure that can store multiple values of the same data type under a single variable name. All the elements of an array are stored in contiguous (continuous) memory locations, which allows easy access using index numbers.
Each element in an array is identified by its index, and indexing starts from 0 in C language.
3. What is array initialization?
Answer:
Array initialization is the process of assigning values to the elements of an array for the first time. It can be done either at the time of declaration or later in the program using assignment statements.
When values are assigned during declaration, the array is immediately ready to use.
Example (Initialization at declaration):
4. Name the three types of loops in C language.
Answer:
In C programming, there are three main types of loops used to repeat a set of instructions:
-
For loop – Typically used when the number of iterations is known in advance.
-
While loop – Repeats a block of code as long as a condition remains true; the condition is checked before each iteration.
-
Do-while loop – Similar to the while loop, but the condition is checked after the code block executes, so the loop executes at least once.
Example (for loop):
printf(“%d “, i);
}
Example (while loop):
while(i < 5) {
printf(“%d “, i);
i++;
}
Example (do-while loop):
do {
printf(“%d “, i);
i++;
} while(i < 5);
Long Questions – Unit 4 Data and Repetition
Q1: What is a Loop Structure? Explain its types in C language.
Introduction:
In programming, a loop is a control structure that allows a set of statements to repeat multiple times without rewriting them. Loops make programs efficient, time-saving, and help avoid code duplication.
Definition:
A loop structure in C is a control structure that repeats a block of code until a specified condition is met.
Types of Loops in C:
1. For Loop
The for loop is used when the number of repetitions is known before the loop starts. It consists of three parts: initialization, condition, and increment/decrement. The loop runs as long as the condition is true.
Syntax:
// Code to repeat
}
Example:
printf(“%d\n”, i);
}
Output: 1 2 3 4 5
Explanation: The for loop is ideal for fixed iterations, such as counting numbers or processing arrays where the total number of repetitions is already known.
2. While Loop
The while loop is used when the number of repetitions is not known in advance. The condition is checked before each iteration, and the loop executes only if the condition is true.
Syntax:
// Code to repeat
}
Example:
while(i <= 5) {
printf(“%d\n”, i);
i++;
}
Output: 1 2 3 4 5
Explanation: The while loop is perfect for situations where the loop should continue until a dynamic condition changes, like reading input until a user enters a specific value.
3. Do-While Loop
The do-while loop guarantees that the loop executes at least once, even if the condition is false. The code block executes first, then the condition is checked. If the condition is true, the loop repeats; otherwise, it stops.
Syntax:
// Code to repeat
} while(condition);
Example:
do {
printf(“%d\n”, i);
i++;
} while(i <= 5);
Output: 1 2 3 4 5
Explanation: The do-while loop is useful when we need the code to run at least once, such as in menu-driven programs or input validation.
Key Points to Remember:
-
For loop: Best for known repetitions.
-
While loop: Best for unknown repetitions where the condition is checked first.
-
Do-while loop: Executes at least once, then checks the condition.
-
Loops are essential to automate repetitive tasks, manage arrays, and make programs efficient.
Download PDF
Download the complete chapter notes in PDF for easy learning and quick exam revision.
English Medium
Skip to PDF contentThese notes include complete explanations, solved MCQs, short questions, and long questions for Unit 4 – Data and Repetition.
Urdu Medium
Skip to PDF contentThese notes are also available in Urdu medium for better understanding and exam preparation.