Important Introduction to Programming Short Questions
Chapter: 6
Question 1:
How can you calculate the sum of odd integers within a given range?
Answer:
By using a loop that checks if a number is odd (not divisible by 2) and summing only those numbers.
Chapter: 6
Question 2:
What is the purpose of indentation in a 'while' loop?
Answer:
Indentation in a 'while' loop enhances code readability, making the structure and flow of the loop clearer.
Chapter: 6
Question 3:
How is a flowchart structured for a 'while' loop?
Answer:
A flowchart for a 'while' loop typically includes a decision diamond for the loop condition and rectangles for the repeated process, with arrows indicating the flow.
Chapter: 6
Question 4:
What is the potential issue with using a fixed limit in a loop?
Answer:
A fixed limit can make the program less flexible, requiring code changes for different ranges or use cases.
Chapter: 6
Question 5:
What is a runtime error and when might it occur in a loop?
Answer:
A runtime error occurs during program execution, possibly due to issues like overflow when handling large sums in a loop.
Chapter: 7
Question 6:
What happens if the condition in a while loop is false initially?
Answer:
The loop does not execute, and control moves to the statement after the closed brace of the while loop.
Chapter: 7
Question 7:
In a while loop, when is the condition tested?
Answer:
The condition is tested before the loop's body is executed.
Chapter: 7
Question 8:
What is a situation where a do-while loop might be more appropriate than a while loop?
Answer:
A do-while loop is more appropriate when the loop's body must execute at least once regardless of the condition.
Chapter: 7
Question 9:
When is the condition in a do-while loop tested?
Answer:
The condition in a do-while loop is tested after the loop body is executed.
Chapter: 7
Question 10:
What ensures that the loop body in a do-while loop executes at least once?
Answer:
The loop body executes at least once because the condition is checked after the body has executed.