#1
What does a conditional statement do in programming?
It repeats a block of code multiple times.
It executes a block of code based on a condition.
It defines a function in the program.
It initializes a variable in the program.
#2
Which symbol is commonly used to represent 'equal to' in a conditional statement?
#3
What is the purpose of the 'break' statement in a switch statement?
To exit the entire loop.
To exit the switch statement and continue with the code after the switch.
To skip the current case and proceed to the next one.
To stop the execution of the program.
#4
Which of the following is true about the 'if' statement in programming?
It must always be followed by an 'else' statement.
It must always include a condition.
It can stand alone without any accompanying statements.
It must always include multiple conditions.
#5
What does the 'nested if' statement refer to in programming?
A single if statement nested within another if statement
An if statement with multiple conditions separated by logical operators
A series of if statements arranged in a nested structure
An if statement that contains both 'if' and 'else' blocks
#6
Which of the following is true about the 'not' operator in Python?
It reverses the logical value of the operand
It performs bitwise negation on the operand
It checks if two operands are equal
It performs logical OR operation
#7
In a typical if-else statement, what happens if the condition inside the if statement evaluates to false?
The code inside the if block is executed.
The code inside the else block is executed.
The code inside the if block is ignored.
The program throws an error.
#8
What is the purpose of the 'else if' statement in programming?
To terminate the program.
To handle multiple conditions sequentially.
To execute the code only if a certain condition is true.
To ignore all conditions and execute a default block of code.
#9
Which of the following is NOT a logical operator in programming?
AND (&&)
OR (||)
XOR (^)
CON (==)
#10
What does the ternary operator in programming do?
It performs arithmetic operations on three operands.
It evaluates a condition and returns one of two possible values based on the result.
It converts decimal numbers to binary numbers.
It combines multiple conditions into a single expression.
#11
In a switch statement, what happens if none of the cases match the value being evaluated?
The program throws an error.
The default case is executed.
The program terminates.
The program skips the switch statement.
#12
What is the purpose of the 'elif' statement in Python?
To terminate the program if a condition is met.
To handle multiple conditions sequentially after an if statement.
To create a loop in the program.
To define a function with multiple parameters.
#13
What is the result of the following code snippet in Python?
x = 10
y = 20
z = 30
if x > y and x > z:
print('x is the largest number')
elif y > x and y > z:
print('y is the largest number')
else:
print('z is the largest number')
x is the largest number
y is the largest number
z is the largest number
There will be a syntax error.
#14
Which of the following is a common mistake when writing conditional statements?
Not using parentheses to define the condition
Using semicolons instead of colons at the end of the condition
Nesting multiple else statements within each other
Using '===' instead of '==' for comparison in Python
#15
What is the purpose of the 'default' case in a switch statement?
To provide an alternative case for when none of the other cases match
To terminate the switch statement
To indicate the end of the switch statement
To skip the execution of the switch statement
#16
What is the result of the following code snippet in JavaScript?
var x = 10;
var y = 20;
var z = 30;
if (x > y) {
console.log('x is greater than y');
} else if (y > z) {
console.log('y is greater than z');
} else {
console.log('z is greater than x and y');
}
x is greater than y
y is greater than z
z is greater than x and y
No output
#17
In Python, what is the purpose of the 'pass' statement within a conditional block?
To skip the current iteration of a loop
To exit the loop immediately
To indicate that no action should be taken
To raise an exception
#18
What is the primary difference between the 'if' statement and the 'if-elif-else' statement in Python?
The 'if' statement can have multiple conditions, while 'if-elif-else' can have only one
The 'if' statement is used for sequential condition checking, while 'if-elif-else' can handle parallel conditions
There is no difference between the two statements
The 'if-elif-else' statement can have multiple conditions, while 'if' can have only one
#19
What does the 'switch' statement do in programming?
It iterates over elements in a list.
It converts strings to integers.
It allows multiple conditions to be tested against a single value.
It performs mathematical calculations.
#20
What is short-circuit evaluation in the context of conditional statements?
It refers to evaluating only the first condition in a series of conditions.
It refers to skipping the evaluation of conditions if the first condition is false.
It refers to executing all conditions in a series regardless of their results.
It refers to evaluating conditions in a loop until a true condition is found.
#21
What does the '?:' operator represent in C-based languages?
The ternary operator
The bitwise XOR operator
The bitwise AND operator
The logical OR operator
#22
In a switch statement, can multiple case labels share the same block of code?
Yes, but only if the case labels are consecutive.
No, each case label must have its own block of code.
Yes, case labels can share a block of code regardless of their values.
Yes, but only if they have the same value.
#23
Which of the following statements is true about the 'unless' statement in Ruby?
It is equivalent to the 'if' statement
It executes the code block if the condition is true
It executes the code block if the condition is false
It is not a valid statement in Ruby
#24
What is the purpose of the 'case' keyword in a switch statement?
To specify the condition to be evaluated
To indicate the beginning of a new case
To assign a value to a variable
To define a default case
#25
In C++, what happens if no 'break' statement is used in a switch case?
The program throws an error
The program proceeds to execute the next case regardless of the condition
The program ignores the current case and proceeds to execute the default case
The program exits the switch statement immediately