2nd year Computer Chapter 12 Loop Constructs Question An Answer
Short An Simple Question An Answer
Q 1. What is a Control Structure?
Ans. A control structure is a statement used to manage the flow of execution in a program or function, combining individual instructions into a single logical unit. It ensures that program logic is implemented with precision. There are three primary types of control structures:
- Sequence structure
- Selection structure
- Repetition structure
Q 2. What is a Sequence Structure?
Ans. In a sequence structure, program instructions execute one after another, following the order in which they are written. This represents the default flow of a program, where execution starts from the first instruction and proceeds sequentially.
Q 3. What is a Selection Structure?
Ans. A selection structure divides program instructions into two or more groups, executing a selected group based on the evaluation of a specific condition.
Q 4. What is a Repetition Structure?
Ans. A repetition structure, also known as an iteration or loop structure, is used to repeatedly execute a statement or set of statements as long as a given condition remains true. This control structure is ideal for performing repetitive tasks and includes three fundamental loop structures in C language:
- While loop
- Do-while loop
- For loop
Q 5. What is an IF Statement?
Ans. “if” is a keyword in C language, and the “if” statement serves as the simplest form of a selection structure. It is used to execute or skip a statement or a set of statements after evaluating a specific condition, typically a logical or relational expression. If the condition is true, the statements following the “if” statement are executed; if false, they are skipped.
Q 6. What is a Compound Statement?
Ans. A compound statement, also referred to as a block of code, consists of a set of statements enclosed within curly brackets.
Q 7. What is an if-else Statement?
Ans. The “if” statement is employed to make decisions regarding whether a particular task will be performed or not. When a two-way decision is required, the if-else statement is used. It evaluates a condition and executes one of two code blocks, while skipping the other. Both code blocks cannot be executed or skipped.
Q 8. What is an if-else-if Statement?
Ans. The if-else-if statement is used to select and execute one compound statement from two or more available statements. When multiple compound statements are present and you need to choose one, the if-else-if statement is employed.
Q 9. What is a Conditional Operator?
Ans. The conditional operator is used as an extension of a simple if-else statement to make a two-way decision. It evaluates a condition, and depending on the result, it selects and executes one of two specified statements.
Q 10. What is a Switch Statement?
Ans. A switch statement serves as an alternative to the if-else-if statement and is used for conditional decision-making. It is particularly useful when you need to execute a block of statements from multiple options. The switch statement evaluates an expression and selects the appropriate case based on the evaluated value.
Q 11. What is a Nested if Statement?
Ans. A nested if statement occurs when one “if” statement is used within another “if” statement. This structure is used to create more complex decision-making scenarios by nesting one if statement inside another.
Q 12. What is a Break Statement?
Ans. The “break” statement is a keyword used within a switch statement. It is the final statement within each case and is employed to exit the current code block. When the break statement is executed in a switch statement, it transfers the flow of control to the first instruction after the switch block.
Once upon a time, in the depths of the wood, There lived a young girl, so kind and so good.Her name was Little Red.https://t.me/rutor/13580
Once upon a time, in the depths of the wood, There lived a young girl, so kind and so good.Her name was Little Red.https://t.me/rutor/13580