Core9X
Log inSign up

MBOSE Class X Computer Science · Chapter 10

C++ Control Structures

Live now

How C++ programs make decisions with if and switch, and repeat tasks with for, while and do-while loops.

21 lessons · 110 practice questions

Start freeLog inSign up free: the first chapter of every subject is open.

What this chapter covers

  • Sequence, selection and iteration
  • If, if-else, nested if, else-if ladder
  • Switch-case with break and default
  • For, while and do-while loops
  • Entry- and exit-controlled loops
  • Indefinite loops
  • Nested loops
  • Break, continue, goto and exit()
  • Standard programs
  • Dry runs, output and debugging questions

Key terms

control structure

Meaning: decides the order of execution

Example: if, for

selection

Meaning: choosing statements by a condition

Example: if…else

iteration

Meaning: repeating statements

Example: loops

nested if

Meaning: an if inside another if

else-if ladder

Meaning: chain of conditions

Example: grades

switch

Meaning: chooses among many constant cases

Example: menu

fall-through

Meaning: running into the next case without break

loop variable

Meaning: variable that controls a loop

Example: i

entry-controlled loop

Meaning: condition tested before the body

Example: while, for

exit-controlled loop

Meaning: condition tested after the body

Example: do…while

indefinite loop

Meaning: loop that never ends

Example: missing i++

nested loop

Meaning: loop inside a loop

Example: patterns

Important questions with answers

10 of the 110 questions on this chapter, solved.

  1. Question 1 · Multiple choice · 1 mark

    The control structure in which statements run one after another in order is

    • (a) iteration
    • (b) selection
    • (c) sequence
    • (d) jump

    Answer: (c) sequence

    Selection decides; iteration repeats.

  2. Question 2 · Multiple choice · 1 mark

    If d = b² − 4ac is less than 0, the roots are

    • (a) imaginary (not real)
    • (b) real and equal
    • (c) real and unequal
    • (d) zero

    Answer: (a) imaginary (not real)

    SSLC 2022, Q10(a).

  3. Question 3 · Multiple choice · 1 mark

    In a for loop, the initialisation is done

    • (a) after every pass
    • (b) before every pass
    • (c) only once, at the start
    • (d) never

    Answer: (c) only once, at the start

    The condition is tested before every pass; the update runs after every pass.

  4. Question 4 · Multiple choice · 1 mark

    The output of for (i = 1; i <= 5; i++) { if (i == 3) continue; cout << i; } is

    • (a) 12
    • (b) 1245
    • (c) 12345
    • (d) 345

    Answer: (b) 1245

    Only 3 is skipped.

  5. Question 5 · Assertion and reason · 1 mark

    Assertion (A): A do…while loop runs at least once.

    Reason (R): Its condition is tested after the body.

    • (a) Both A and R are true, and R is the correct explanation of A.
    • (b) Both A and R are true, but R is not the correct explanation of A.
    • (c) A is true, but R is false.
    • (d) A is false, but R is true.

    Answer: (a) Both A and R are true, and R is the correct explanation of A.

    It is exit-controlled.

  6. Question 6 · Short answer · 2 marks

    Differentiate between while and do…while loops.

    Answer

    while is entry-controlled (may run zero times); do…while is exit-controlled (runs at least once) and ends with while (condition);.

  7. Question 7 · Short answer · 2 marks

    Write the output: int a = 0; while (a < 10) { if (a == 5) break; cout << a; a++; }

    Answer

    01234

  8. Question 8 · Short answer · 3 marks

    Write the output and explain: for (i = 1; i <= 5; i++) { if (i == 3) continue; cout << i; }

    Answer

    1245. When i is 3, continue skips the cout and goes to the next pass.

  9. Question 9 · Long answer · 5 marks

    Write a C++ program to print the factors of a number entered by the user.

    Answer

    #include <iostream>
    using namespace std;
    int main()
    {
        int n, i;
        cout << "Enter a number: ";
        cin >> n;
        for (i = 1; i <= n; i++)
            if (n % i == 0)
                cout << i << " ";
        return 0;
    }
    
  10. Question 10 · Long answer · 5 marks

    Write a C++ program to print the multiplication table of a number using a while loop.

    Answer

    #include <iostream>
    using namespace std;
    int main()
    {
        int n, i = 1;
        cout << "Enter a number: ";
        cin >> n;
        while (i <= 10)
        {
            cout << n << " x " << i << " = " << n * i << endl;
            i++;
        }
        return 0;
    }
    

Study the whole chapter

21 step-by-step lessons, all 110 practice questions with hints, flashcards and mock tests for MBOSE Class X Computer Science.

Start freeLog inSign up free: the first chapter of every subject is open.