Conditional Statements Quiz - CBSE Class 8 ICT
Free practice quiz: Conditional Statements (CBSE Class 8 ICT). 20 multiple-choice questions with answers and explanations. Play online, no sign-up needed.
Play all 20 questions freeSample questions
What is a conditional statement in programming?
- A statement that executes unconditionally
- A statement that executes based on a condition
- A statement that can be used to repeat actions
- A statement that defines variables
Show answer
Answer: B. A statement that executes based on a condition
A conditional statement allows execution of certain parts of the code based on whether a condition is true or false, making it a key concept in programming.
What will the following code print? if (true) { console.log('Yes'); } else { console.log('No'); }
- Yes
- No
- Nothing
- Error
Show answer
Answer: A. Yes
Since the condition is 'true', the first block will execute, printing 'Yes' to the console.
What will be the output of the following code block? var a = 10; if (a == 10) { console.log('Ten'); } else { console.log('Not Ten'); }
- Ten
- Not Ten
- Error
- Nothing
Show answer
Answer: A. Ten
The value of a is equal to 10, so the condition is true, and 'Ten' will be printed.
What will happen if none of the if or else-if conditions are satisfied?
- The program will stop
- An error will occur
- The else block will execute if present
- Nothing will happen
Show answer
Answer: C. The else block will execute if present
If all if and else-if conditions are false, the else block, if defined, will execute, allowing for a default action.
How can an 'if' statement be terminated in programming?
- With a semicolon ;
- With a period .
- With a comma ,
- With a curly brace }
Show answer
Answer: D. With a curly brace }
An 'if' statement block in most programming languages is terminated by a curly brace to signify the end of the conditional block.