1.
Is the following statement true or false? Statement: The default statement in a switch ... case construct has a single break statement.
Correct Answer
B. False
Explanation
In a switch ... case construct, the default statement does not necessarily have a single break statement. The default statement is executed when none of the other cases match the given value. It can have multiple statements or even no statements at all. The break statement is used to exit the switch block, but it is not required in the default statement. Therefore, the given statement is false.
2.
A ______________ construct is used to repeat the execution of a section of a program.
Correct Answer
D. Loop
Explanation
A loop construct is used to repeat the execution of a section of a program. Loops allow a programmer to repeat a set of instructions multiple times until a certain condition is met. This helps in automating repetitive tasks and makes the code more efficient. The loop construct is an essential part of programming as it allows for better control over the flow of the program and enables the execution of a section of code multiple times without having to write the same code over and over again.
3.
Which of the following are loop constructs? (Choose all that apply)
Correct Answer(s)
A. Goto
B. For loop
D. Repeat...until loop
E. While
Explanation
The loop constructs in the given options are "for loop", "repeat...while loop", and "while loop". These constructs are used in programming to repeat a block of code until a certain condition is met. The "for loop" is used to iterate a specific number of times, the "repeat...while loop" is used to repeat a block of code until a condition is true, and the "while loop" is used to repeat a block of code while a condition is true. The "goto" statement is not a loop construct but a control transfer statement used to jump to a specific line of code.
4.
The body of the while loop is continuously executed until the specified condition is _______.
Correct Answer
B. True
Explanation
The body of the while loop is continuously executed until the specified condition is evaluated as true. This means that as long as the condition remains true, the loop will continue to execute. Once the condition becomes false, the loop will exit and the program will move on to the next line of code after the loop.
5.
Is the following statement true or false? Statement: The while loop and repeat...until loop differ only in the way the condition is evaluated
Correct Answer
A. True
Explanation
The statement is true. The while loop and repeat...until loop are similar in that they both involve repeating a block of code until a certain condition is met. However, the difference lies in how the condition is evaluated. In a while loop, the condition is checked before the loop is executed, while in a repeat...until loop, the condition is checked after the loop is executed. This means that a while loop may not execute at all if the condition is initially false, while a repeat...until loop will always execute at least once before checking the condition.
6.
What are the three components of the for loop? (Choose all that apply)
Correct Answer(s)
A. Intialization expression
C. Evaluation Expression
D. Increment/Decrement expression
Explanation
The three components of the for loop are the initialization expression, the evaluation expression, and the increment/decrement expression. The initialization expression is used to initialize the loop control variable, the evaluation expression is used to determine whether the loop should continue or terminate, and the increment/decrement expression is used to modify the loop control variable after each iteration. These three components work together to control the flow of the loop and determine how many times it will iterate. The result expression is not a component of the for loop.
7.
Identify whether the following statements are true or false. Statement 1: The initialization in the for statement is done only once. Statement 2: The goto is used when the number of iterations of the loop is known before.
Correct Answer
C. Statement 1 is true and Statement 2 is false
Explanation
Statement 1 is true because the initialization in the for statement is done only once at the beginning of the loop and not repeated for each iteration. Statement 2 is false because the goto statement is not used when the number of iterations of the loop is known beforehand. The goto statement is used for unconditional jumps within a program and is not specific to loops.
8.
There are techniques that provide ways to split a long, continuous program into a series of individual _________ that are related to each other in a specified manner.
Correct Answer
B. Modules
Explanation
Modules are units of code that can be used to divide a long, continuous program into smaller, manageable parts. These modules are designed to be related to each other in a specified manner, allowing for better organization and maintainability of the overall program. By breaking down a program into modules, it becomes easier to understand and debug, as well as promote code reusability. Therefore, modules are a suitable explanation for the correct answer.
9.
Which of the following syntax is used to declare a procedure?
Correct Answer
C. Procedure
Explanation
The correct answer is "procedure". In programming, the keyword "procedure" is commonly used to declare a procedure or a subroutine. A procedure is a block of code that performs a specific task and can be called multiple times throughout the program. By declaring a procedure using the "procedure" keyword, it allows the programmer to define the code that will be executed when the procedure is called.
10.
What do you call a specific instruction designed to do a task?
Correct Answer
A. Command
Explanation
A command is a specific instruction given to perform a task. It is a directive that tells someone or something what to do. In this context, a command refers to a specific instruction designed to accomplish a particular task. It is different from a process, which is a series of actions or steps taken to achieve a goal, and a task, which is a piece of work that needs to be done. An instruction, on the other hand, is a general term that can encompass any type of guidance or direction given to someone.