Skip to content
Computer ScienceISC Class 12 · Chapter 8

Statements and Scope in Java: ISC Class 12 Computer Science

Updated 15 October 2026 · Fact-checked

Java statements control the flow of a program: conditionals (if, if-else, if-else-if, switch-case, the ternary operator) choose between actions, and loops (for, while, do-while, with break and continue) repeat them. Statements are grouped into blocks, and a variable's scope is the block in which it is declared and visible.

What Statements, Scope is about

The syllabus asks for:
1. Conditional statements: if, if-else, if-else-if, switch-case, ternary operator.
2. Looping: for, while, do-while, continue, break.
3. Grouping statements in blocks; scope and visibility of variables.

In the paper these appear everywhere: output and dry-run questions, assertion-reason items (for example on break and fall-through in switch), fill-in-the-blank methods in Question 2 (recent papers used a smallest-digit method and a duck-number method), and every Section B program.

All code on this page was compiled and run; the outputs shown are exactly what it printed.

Weightage: CISCE publishes no chapter or unit weightage for ISC Computer Science. Statements, Scope is part of Section B, 8 of the 2027 syllabus and can be asked anywhere in the 70-mark Paper 1 (Part I compulsory: ten 1-mark items and a 10-mark short-answer question; Part II: two of three 10-mark questions in each of Sections A and B, and two of three 5-mark questions in Section C).Source: CISCE ISC Computer Science (868) syllabus, examination year 2027; latest Paper 1 specimen (2025) and the 2025 board paper

Key concepts

Conditional statements

1. if: runs a statement or block only when the condition is true.
2. if-else: chooses between two alternatives.
3. if-else-if ladder: tests conditions in order and runs the first true branch; a final else handles all remaining cases.
4. Nested if: an if inside another; an else belongs to the nearest unmatched if (use braces to make the intended pairing clear: the 'dangling else').
5. Ternary operator: condition ? a : b gives a value, so it can be used inside expressions: int big = m > n ? m : n;
6. switch-case: selects a branch by comparing one expression with constant case labels.

  • The expression may be int (and byte, short, char), String (Java 7 onwards) or an enum; not long, float, double or boolean.
  • Case labels must be distinct constants.
  • Without break, execution falls through into the following cases (useful for grouping cases that share code).
  • default runs when no case matches; it is optional and can appear anywhere.

switch versus if-else-if: switch tests equality of one expression against constants only; if-else-if can test any conditions, including ranges.

Worked example

[2] State two differences between switch-case and an if-else-if ladder. (Understand)

Try it first, then show the solutionSolution
  1. switch tests only equality of one expression with constant values; if-else-if can test any relational or logical conditions, including ranges - 1 mark.
  2. switch works with int, char, String (and similar) but not double or boolean; without break it falls through, which does not happen in if-else-if - 1 mark.

Answer: switch compares one expression for equality with constant case labels and works only with int-type, char, String or enum values, falling through without break; an if-else-if ladder can test any conditions (ranges, several variables, doubles) and runs only the first true branch.

Loops, break and continue

1. for (init; condition; update) { body }: best when the number of iterations is known.
2. while (condition) { body }: entry-controlled; the body may run zero times.
3. do { body } while (condition);: exit-controlled; the body runs at least once (note the semicolon).

Infinite loop: a loop whose condition never becomes false (for (;;), while (true), or a missing update).

break: exits the nearest enclosing loop or switch immediately. A labelled break (break outer;) exits the named outer loop.
continue: skips the rest of the current iteration and goes to the next one (in a for loop, the update still runs).

// switch with and without break, break and continue in loops, nested loop with a labelled break.
public class Flow
{
    public static void main(String[] args)
    {
        int code = 2;
        switch (code)             // no break after case 2: falls through to case 3
        {
            case 1:
                System.out.print("one ");
            case 2:
                System.out.print("two ");
            case 3:
                System.out.print("three ");
                break;
            default:
                System.out.print("other ");
        }
        System.out.println();

        for (int i = 1; i <= 10; i++)
        {
            if (i % 3 == 0)
                continue;         // skip multiples of 3
            if (i > 8)
                break;            // stop the loop completely
            System.out.print(i + " ");
        }
        System.out.println();

        outer:
        for (int r = 1; r <= 3; r++)
        {
            for (int c = 1; c <= 3; c++)
            {
                if (r * c == 4)
                    break outer;  // leaves both loops
                System.out.print(r * c + " ");
            }
        }
        System.out.println();

        int n = 0;
        while (n < 3)
            n++;                  // only this statement is in the loop body
        System.out.println("n = " + n);
    }
}

Output:

two three 
1 2 4 5 7 8 
1 2 3 2 
n = 3

Explanation: code 2 prints 'two' and falls through to 'three' until break. The for loop skips 3, 6, 9 with continue and stops at 10 with break. The labelled break leaves both loops as soon as r × c = 4. Without braces, only n++ belongs to the while loop.

Worked example

[2] What is printed by for (int i = 1; i <= 10; i++) { if (i % 3 == 0) continue; if (i > 8) break; System.out.print(i + " "); } ? (Apply)

Try it first, then show the solutionSolution
  1. Multiples of 3 (3, 6, 9) are skipped by continue - 1 mark.
  2. At i = 10, i > 8 so the loop breaks; output 1 2 4 5 7 8 - 1 mark.

Answer: 1 2 4 5 7 8

Blocks, scope and visibility

A block is a group of statements enclosed in braces { }. A method body, a loop body and an if branch are blocks.

Scope of a variable: the region of the program where it can be used.
1. Local variable: from its declaration to the end of the block in which it is declared. A loop variable declared in a for header exists only inside that loop.
2. Parameter: the whole method body.
3. Instance variable: all instance methods of the class (and other classes, depending on the access modifier).
4. Class (static) variable: all methods of the class, including static ones.

Lifetime: local variables are created when the block is entered and destroyed when it ends; instance variables live as long as their object; static variables live while the class is loaded.

Rules:

  • A local variable or parameter with the same name as a field hides (shadows) the field; use this.name to reach the field.
  • Two local variables with the same name cannot be in scope at the same time in one method (a block variable cannot redeclare a variable of the enclosing block), but the same name can be reused after the first one's block has ended.

Visibility (access modifiers): private (own class only), default (same package), protected (same package and subclasses), public (everywhere).

// Scope and visibility: instance, static, local and block variables; shadowing.
public class Scope
{
    int value = 10;               // instance variable: visible in all instance methods
    static int shared = 1;        // class variable

    void test(int value)          // the parameter shadows the instance variable
    {
        System.out.println("parameter value = " + value);
        System.out.println("field value     = " + this.value);
        for (int i = 0; i < 2; i++)
        {
            int sq = i * i;       // sq exists only inside this block
            shared += sq;
        }
        // System.out.println(i);  // would not compile: i is out of scope here
        System.out.println("shared = " + shared);
        {
            int temp = 99;        // block-local variable
            System.out.println("temp = " + temp);
        }
        int temp = 5;             // legal: the earlier temp's block has ended
        System.out.println("temp again = " + temp);
    }

    public static void main(String[] args)
    {
        Scope ob = new Scope();
        ob.test(3);
    }
}

Output:

parameter value = 3
field value     = 10
shared = 2
temp = 99
temp again = 5

shared starts at 1 and gains 0 and 1 (squares of i = 0, 1), ending at 2. The second temp is legal because the first one's block had already ended.

Worked example

[2] In the Scope program, why does the line System.out.println(i); after the for loop fail to compile, and what does this.value print? (Analyse)

Try it first, then show the solutionSolution
  1. i is declared in the for header, so its scope ends with the loop; it cannot be used afterwards - 1 mark.
  2. The parameter value (3) shadows the field; this.value refers to the instance variable, which is 10 - 1 mark.

Answer: i is out of scope after the loop, so the compiler rejects the line; this.value prints the field's value 10, while value alone gives the parameter 3.

Tracing and completing code with conditions and loops

Question 2 often gives a method with blanks. Strategy:
1. Read the comment or description: what should the method return?
2. Identify each variable's role (counter, accumulator, flag, minimum, current digit).
3. Fill blanks so that the loop starts, continues and stops correctly, and so that the flag or accumulator has a sensible starting value.
4. Test with one or two values by tracing.

Example: a Spy number has equal sum and product of digits (1124: 1 + 1 + 2 + 4 = 8 and 1 × 1 × 2 × 4 = 8).

boolean isSpy(int n)
{
    int sum = 0, prod = 1;
    for (int t = n; t > 0; t = t / 10)
    {
        int d = t % 10;
        sum = sum + d;
        prod = prod * d;
    }
    return sum == prod;
}

Key choices: prod starts at 1 (0 would make every product 0); the update t = t / 10 changes the loop variable itself; the test uses ==. isSpy(1124) and isSpy(123) are both true (for 123: 1 + 2 + 3 = 6 = 1 × 2 × 3), while isSpy(124) is false (sum 7, product 8).

Worked example

[3] In isSpy above, the lines are replaced by ?1? for the initial value of prod, ?2? for the loop update and ?3? for the return expression. State them and give isSpy(124). (Apply)

Try it first, then show the solutionSolution
  1. ?1? = 1 (the identity for multiplication) - 1 mark.
  2. ?2? = t = t / 10 (or t /= 10) - 1 mark.
  3. ?3? = sum == prod; for 124: sum 7, product 8, so false - 1 mark.

Answer: ?1? = 1; ?2? = t = t / 10; ?3? = sum == prod. isSpy(124) returns false (7 ≠ 8).

A complete program with switch, loops and validation

Converting a day number of a year into a date uses an if for validation, a switch with grouped cases for month lengths, a while loop to subtract months, and a leap-year test:
leap year: divisible by 4 and not by 100, or divisible by 400.

import java.util.Scanner;

// Converts a day number (1-365 or 1-366) of a given year into a date.
public class DayToDate
{
    int day, year;

    DayToDate()
    {
        day = 0;
        year = 0;
    }

    void accept()
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter day number and year:");
        day = sc.nextInt();
        year = sc.nextInt();
    }

    boolean isLeap(int y)
    {
        return (y % 4 == 0 && y % 100 != 0) || y % 400 == 0;
    }

    int daysIn(int m)
    {
        switch (m)
        {
            case 2:
                return isLeap(year) ? 29 : 28;
            case 4:
            case 6:
            case 9:
            case 11:
                return 30;        // grouped cases share one statement
            default:
                return 31;
        }
    }

    String monthName(int m)
    {
        String name;
        switch (m)
        {
            case 1: name = "January"; break;
            case 2: name = "February"; break;
            case 3: name = "March"; break;
            case 4: name = "April"; break;
            case 5: name = "May"; break;
            case 6: name = "June"; break;
            case 7: name = "July"; break;
            case 8: name = "August"; break;
            case 9: name = "September"; break;
            case 10: name = "October"; break;
            case 11: name = "November"; break;
            default: name = "December";
        }
        return name;
    }

    void convert()
    {
        int limit = isLeap(year) ? 366 : 365;
        if (day < 1 || day > limit)
        {
            System.out.println("Invalid day number");
            return;
        }
        int m = 1, d = day;
        while (d > daysIn(m))
        {
            d = d - daysIn(m);
            m++;
        }
        System.out.println("Day " + day + " of " + year + " is " + d + " " + monthName(m) + " " + year);
    }

    public static void main(String[] args)
    {
        DayToDate ob = new DayToDate();
        ob.accept();
        ob.convert();
    }
}

Input: 255 2024

Enter day number and year:
Day 255 of 2024 is 11 September 2024

Other runs: 255 2025 → 12 September 2025 (non-leap year, so one day later); 60 2024 → 29 February 2024; 366 2023 → Invalid day number; 365 2026 → 31 December 2026.

The switch in daysIn( ) groups cases 4, 6, 9 and 11 by letting them fall through to one return statement; monthName( ) uses break after each case.

Worked example

[2] Trace convert( ) for day 60 of 2024 and give the output. (Apply)

Try it first, then show the solutionSolution
  1. d = 60 > 31 (January) → d = 29, m = 2 - 1 mark.
  2. 2024 is a leap year, so February has 29 days; 29 > 29 is false, loop stops: 29 February 2024 - 1 mark.

Answer: Day 60 of 2024 is 29 February 2024.

Statements, Scope in real life

Each concept, met in an everyday situation. Read the situation, answer the question in your own words, then compare with the model answer. The one-line hook is what to remember.

switch fall-through

Imagine a lift that, when you press floor 2, is supposed to stop only at 2 but also stops at every floor above until something tells it to halt.

Which programming mistake behaves like this?

Try it first, then show the solutionSolution
  1. A switch case without break continues into the next cases.
  2. break is the 'halt' that stops at the matching case.

Answer: A missing break in a switch: execution falls through to the following cases until a break or the end of the switch.

Memory hook: No break, no brakes.

Scope

Suppose a visitor's pass works only inside one building, while staff passes work across the whole campus.

How does this compare with local and instance variables?

Try it first, then show the solutionSolution
  1. A local variable is like the visitor's pass: valid only inside its block.
  2. An instance variable is like the staff pass: usable in every method of the object.

Answer: Local variables are usable only in their own block (like a building pass), while instance and static variables are visible throughout the class (like a campus pass).

Memory hook: Declared inside the braces, lives inside the braces.

continue versus break

Imagine checking a pile of exam papers: you skip any paper with no name and move on, but stop altogether when the bell rings.

Which statement matches each action?

Try it first, then show the solutionSolution
  1. Skipping one paper and moving to the next is continue.
  2. Stopping the whole job is break.

Answer: Skipping an item is continue; stopping the loop is break.

Memory hook: continue skips one; break stops all.

Topics in this chapter

Statements, Scope: syntax and key facts

Leap year
(y % 4 == 0 && y % 100 != 0) || y % 400 == 0
2024 leap; 1900 not; 2000 leap.
switch types
int, short, byte, char, String, enum (not long, float, double, boolean)
Case labels: distinct constants.
Loop types
for (known count); while (0 or more); do-while (1 or more)
do-while ends with ;
break / continue
break: exit loop or switch; continue: next iteration
Labelled break exits an outer loop.
Scope
Local: declaration to end of its block; field: whole class
this.x reaches a shadowed field.

How the board asks Statements, Scope

The question patterns to expect, and the method that works for each.

Question typeHow it is askedMethod
Assertion-reason and MCQStatements about break, fall-through, do-while, switch types.Judge each statement; then decide if the reason explains the assertion in that context.
Fill in the blanks [3]Methods for digit properties (smallest digit, duck number, spy number) with ?1?-?3?.Correct initial values, loop updates on the loop variable, correct final comparison; test by tracing.
Output prediction [2]Loops with break and continue, nested loops, switch without break.Trace iteration by iteration.
Programs [10]Date conversions, menus, number tests using conditions and loops.Validate input first; use switch for fixed choices and if-else-if for ranges.

Tricks to remember Statements, Scope

Short memory aids. Say each one aloud once, then use it on a question the same day.

  • Ternary as a mini if

    cond ? yes : no.

    Use it when: Reading and writing ?:.

  • Leap rule 4-100-400

    Every 4, except every 100, except every 400.

    Use it when: Leap-year test.

  • Braces decide

    No braces: only the next single statement belongs to the if or loop.

    Use it when: Tracing indentation traps.

Statements, Scope: board-level solved questions

Ordered from board level to HOTS. Cover the solution, write your own, then compare step by step.

Example 1: switch types · 1 mark · MCQBoard level

Which of these cannot be used as the expression of a switch statement?
(a) char
(b) String
(c) double
(d) int

Try it first, then show the solutionSolution
  1. switch accepts int-compatible types, char, String and enums.
  2. double is not allowed.

Answer: (c) double.

Example 2: do-while minimum · 1 mark · Very short answerBoard level

How many times is the body of do { x++; } while (x < 0); executed if x starts at 5?

Try it first, then show the solutionSolution
  1. do-while runs the body before testing.
  2. After one run x = 6; 6 < 0 is false, so it stops.

Answer: Once.

Example 3: Assertion-reason: continue · 1 mark · Assertion-reasonHarder board level

Assertion (A): In a for loop, continue jumps straight to the condition test, skipping the update expression.
Reason (R): continue ends only the current iteration, not the whole loop.
(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.

Try it first, then show the solutionSolution
  1. A is false: in a for loop the update (such as i++) still runs after continue; otherwise for (int i = 0; i < 5; i++) { if (i == 2) continue; k++; } would never finish, yet it ends with k = 4 (checked by running the code).
  2. R is true: continue abandons only the rest of the current iteration, while break leaves the loop.

Answer: (d) A is false but R is true.

Example 4: Nested loop with labelled break · 2 marks · Short answerHarder board level

[2] Give the output of the labelled-break loop in the Flow program (outer r from 1 to 3, inner c from 1 to 3, break outer when r × c = 4, else print r × c). (Apply)

Try it first, then show the solutionSolution
  1. r = 1: prints 1 2 3.
  2. r = 2: c = 1 prints 2; c = 2 gives 4, so break outer ends both loops.

Answer: 1 2 3 2

Example 5: Day number to date · 10 marks · Long answerHOTS / competency

[10] Design a class DayToDate with data members day and year; a constructor; void accept( ); boolean isLeap(int y); int daysIn(int m) using switch-case; String monthName(int m); and void convert( ) that validates the day number and prints the corresponding date. Write main( ). Give the output for 255 2024. (Create)

Try it first, then show the solutionSolution
  1. Data members int day, year; constructor sets both to 0; accept( ) reads them.
  2. isLeap: (y % 4 == 0 && y % 100 != 0) || y % 400 == 0.
  3. daysIn( ): switch with case 2 → 29 or 28; cases 4, 6, 9, 11 grouped → 30; default → 31.
  4. monthName( ): switch from 1 to 12 with break after each case.
  5. convert( ): reject day < 1 or > 365/366; m = 1, d = day; while d > daysIn(m), subtract and move to next month; print d, monthName(m) and year.
  6. main( ): create the object, call accept( ) and convert( ). Output for 255 2024: 'Day 255 of 2024 is 11 September 2024'.

Answer: See the compiled DayToDate program; 255 2024 gives 11 September 2024, while 255 2025 gives 12 September 2025 because 2025 is not a leap year.

Example 6: Dangling else · 2 marks · Short answerHOTS / competency

[2] What is printed when x = 5 and y = -1? if (x > 0) if (y > 0) System.out.println("A"); else System.out.println("B"); Explain. (Analyse)

Try it first, then show the solutionSolution
  1. The else pairs with the nearest unmatched if, i.e. if (y > 0), whatever the indentation.
  2. x > 0 is true; y > 0 is false, so the else runs: prints B.

Answer: B, because the else belongs to the inner if (y > 0).

Case-study practice (Section D style)

Read the situation, then answer every part. In the board paper this is a 6-mark question split into 2 + 2 + 1 + 1 marks.

Menu-driven program (case-based)

A program shows a menu: 1 = area of a circle, 2 = area of a square, 3 = exit. It reads a choice and repeats until 3 is chosen.

  1. (i) · 2 marks

    Which loop is most suitable and why?

    Answer

    Answer: do-while, because the menu must be shown at least once before the choice is tested.

    1 for loop, 1 for reason.

  2. (ii) · 2 marks

    Which conditional statement suits the choice, and what keyword is needed in each case?

    Answer

    Answer: switch-case on the choice, with break after each case to prevent fall-through.

    1 + 1.

  3. (iii) · 1 mark

    How should an invalid choice such as 7 be handled?

    Answer

    Answer: With a default case that prints 'Invalid choice'.

    1 mark.

  4. (iv) · 1 mark

    Write the loop condition.

    Answer

    Answer: while (choice != 3);

    1 mark.

Where the marks are

How a typical answer is split into step marks. Show every step: a right final answer alone rarely earns full marks.

[2] Output with continue and break. (2 marks)

StepMarks
Skipped values identified.1
Correct stopping point and output.1

[5] Numbers divisible by 3 or 5 but not both. (5 marks)

StepMarks
Loop from 1 to 100.1
continue for multiples of 15.2
Condition with ||.1
Count stated with reasoning.1

[10] Class DayToDate. (10 marks)

StepMarks
Data members, constructor, accept( ).1
isLeap( ).1
daysIn( ) with switch and grouped cases.2
monthName( ).1
convert( ) with validation and month loop.3
main( ).1
Documentation.1

Where students lose marks in Statements, Scope

The slips examiners see most often, and what to write instead.

  • Mistake: Wrong starting value in a minimum or product

    CISCE examiners' comments, 2024: in a smallest-digit method candidates 'Took initial min as 0 or -1' and 'Did not realise remainder is obtained as n - q*10 in this code'.

    Do this: Start a minimum at 9 (or the number itself) and a product at 1; recognise that n - (n / 10) × 10 is the same as n % 10.

    Usually costs: 1 mark per blank.

  • Mistake: Loop update that does not change the loop variable

    CISCE examiners' comments, 2025: in the duck-number method candidates 'Wrote i = a/10 or only i/10 instead of i = i/10 for ?1?' and 'Gave vague answers for ?2?'.

    Do this: The update must reassign the loop variable from itself: i = i / 10. Give exact values (0, -1) in blanks, not descriptions.

    Usually costs: 1 mark per blank.

  • Mistake: Confusing break in loops with break in switch

    CISCE examiners' comments, 2025: on break and fall-through, candidates 'Confused between options A and B because of the word loop in the Reason'.

    Do this: break exits whichever loop or switch encloses it; in a switch that is what prevents fall-through.

    Usually costs: 1 mark.

  • Mistake: Using a variable outside its scope

    A for-loop variable or a block variable cannot be used after its block; such answers do not compile.

    Do this: Declare the variable before the loop if it is needed afterwards.

    Usually costs: 1 mark.

Practice questions on Statements, Scope

Write each answer on paper first. Open the hint only if you are stuck, and the answer only when you have finished.

  1. Q1 · 1 mark · Very short answerBoard level

    What is the output of int a = 9; System.out.println(a % 2 == 0 ? "even" : "odd");?

    Hint

    9 % 2.

    Answer

    odd

  2. Q2 · 1 mark · Very short answerBoard level

    Is 1900 a leap year?

    Hint

    Century rule.

    Answer

    No: it is divisible by 100 but not by 400.

  3. Q3 · 1 mark · Very short answerBoard level

    What does continue do in a for loop?

    Hint

    Skips the rest.

    Answer

    It skips the remaining statements of the current iteration, runs the update and goes to the next iteration.

  4. Q4 · 1 mark · Very short answerHarder board level

    Give the output: int s = 0; for (int i = 5; i > 0; i -= 2) s += i; System.out.println(s);

    Hint

    5, 3, 1.

    Answer

    9

  5. Q5 · 2 marks · Short answerHarder board level

    [2] Rewrite using a while loop: for (int i = 10; i >= 1; i -= 3) System.out.print(i + " "); and give the output.

    Hint

    Initialise before, update inside.

    Answer

    int i = 10; while (i >= 1) { System.out.print(i + " "); i -= 3; } Output: 10 7 4 1

  6. Q6 · 3 marks · Short answerHarder board level

    [3] Fill the blanks so that the method returns true if n contains the digit 7: boolean hasSeven(int n) { boolean f = ?1?; while (n > 0) { if (?2?) { f = true; break; } ?3?; } return f; }

    Hint

    Flag starts false.

    Answer

    ?1? = false; ?2? = n % 10 == 7; ?3? = n = n / 10. hasSeven(1729) is true and hasSeven(1234) is false.

  7. Q7 · 5 marks · Long answerHOTS / competency

    [5] Write a method that prints all numbers from 1 to 100 that are divisible by 3 or 5 but not by both, using continue to skip numbers divisible by both, and state how many it prints.

    Hint

    Multiples of 15 are skipped.

    Answer

    for (int i = 1; i <= 100; i++) { if (i % 15 == 0) continue; if (i % 3 == 0 || i % 5 == 0) System.out.print(i + " "); } It prints 41 numbers (33 multiples of 3 + 20 multiples of 5 - 2 × 6 multiples of 15), checked by running the code.

  8. Q8 · 10 marks · Long answerHOTS / competency

    [10] Design a class Grade with data members name and an array of five marks; a constructor; void accept( ); double average( ); char grade( ) using an if-else-if ladder (A: 90 and above, B: 75-89, C: 60-74, D: 40-59, E: below 40) applied to the average; and void report( ). Write main( ).

    Hint

    Test from the highest band down.

    Answer

    Constructor initialises name = "" and the array; accept( ) reads the name and five marks; average( ) returns the sum / 5.0; grade( ): if avg >= 90 'A' else if avg >= 75 'B' else if avg >= 60 'C' else if avg >= 40 'D' else 'E'; report( ) prints name, average and grade; main( ) calls accept( ) and report( ). For marks 78, 85, 91, 66, 70 the average is 78.0 and the grade B (checked by running the code).

Test your recall

Answer in your head or on paper first, then open the card. Pulling an answer out of memory makes it stick far better than re-reading.

  1. 1.Which loop is exit-controlled?Show answer

    do-while.

  2. 2.What happens without break in a switch case?Show answer

    Execution falls through to the next case.

  3. 3.Scope of a for-loop variable?Show answer

    Only inside that loop.

  4. 4.How do you reach a field hidden by a parameter?Show answer

    this.fieldName.

  5. 5.Day 255 of 2024?Show answer

    11 September 2024.

Best order to study it

  1. if, if-else, ladders, nested if and the ternary operator.
  2. switch-case: types, break, fall-through, default.
  3. for, while, do-while; break, continue, labelled break.
  4. Blocks, scope, lifetime, shadowing and access modifiers.
  5. Tracing and fill-in-the-blank practice; full programs.

Quick revision checklist

The night before the exam: can you do each of these without looking?

  • if-else-if: first true branch runs; else pairs with the nearest if.
  • switch: int, char, String, enum; break stops fall-through; default optional.
  • for (count known), while (may be 0), do-while (at least 1).
  • break exits; continue skips to next iteration.
  • Scope: local to its block; fields to the class; this.x for shadowed fields.
  • Leap year: (y % 4 == 0 && y % 100 != 0) || y % 400 == 0.

Statements, Scope: frequently asked questions

Can switch use ranges such as case 1-10?

No. Each case is a single constant. For ranges use an if-else-if ladder, or group several case labels that fall through to one statement.

Is a labelled break in the syllabus?

The syllabus names break and continue. Labelled break is standard Java and useful to know, but questions normally use plain break.

Why does my while loop never end?

Usually the update is missing or does not change the variable in the condition (for example writing i / 10 instead of i = i / 10).

Based on: CISCE ISC 2027 Computer Science (868) syllabus; CISCE ISC Computer Science (868) Paper 1 specimen question paper and answer key (latest specimen, 2025); CISCE Analysis of Pupil Performance, ISC Computer Science (868), 2025; CISCE Analysis of Pupil Performance, ISC Computer Science (868), 2024