Any2Quiz
CBSE / 8 / ICT / Programming Basics

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 free

Sample questions

  1. What is a conditional statement in programming?

    1. A statement that executes unconditionally
    2. A statement that executes based on a condition
    3. A statement that can be used to repeat actions
    4. 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.

  2. What will the following code print? if (true) { console.log('Yes'); } else { console.log('No'); }

    1. Yes
    2. No
    3. Nothing
    4. Error
    Show answer

    Answer: A. Yes

    Since the condition is 'true', the first block will execute, printing 'Yes' to the console.

  3. What will be the output of the following code block? var a = 10; if (a == 10) { console.log('Ten'); } else { console.log('Not Ten'); }

    1. Ten
    2. Not Ten
    3. Error
    4. Nothing
    Show answer

    Answer: A. Ten

    The value of a is equal to 10, so the condition is true, and 'Ten' will be printed.

  4. What will happen if none of the if or else-if conditions are satisfied?

    1. The program will stop
    2. An error will occur
    3. The else block will execute if present
    4. 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.

  5. How can an 'if' statement be terminated in programming?

    1. With a semicolon ;
    2. With a period .
    3. With a comma ,
    4. 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.

Take the full quiz

More quizzes

Browse all Programming Basics quizzes