Looking For Anything Specific?

Free Demo

📚 Book a Free Online Demo Class Now!

Learn with clarity, personal mentorship & expert guidance.

🚀 Book Now

Control Structures (ICSE)

 (a) What is sequential execution of a program?

Ans:  Sequential execution means that the statements in a program are executed one after another in the order in which they are written, from top to bottom, without skipping any statement.

(b) What are control structures? Why do we need them in a program?

Ans: Control structures are the statements that control the flow of execution of a program.

We need control structures to:

Make decisions in a program

Repeat certain instructions

Control the order in which statements are executed

Examples of control structures are conditional statements and loops.

(c) What are conditional statements?

Ans: Conditional statements are statements that execute different blocks of code based on a condition.

If the condition is true, one block of code runs; if it is false, another block runs.

Examples: if, if-else, if-else-if

(d) Differentiate between if and if-else statements. Give suitable examples.

Ans: if statement:

It executes a block of code only when the condition is true.

If the condition is false, nothing happens.

Example:

if (age >= 18) {

    System.out.println("Eligible to vote");

}

if-else statement:

It executes one block of code when the condition is true and another block when the condition is false.

Example:

if (age >= 18) {

    System.out.println("Eligible to vote");

} else {

    System.out.println("Not eligible to vote");

}

(e) What is the use of the if-else-if ladder?

Ans: The if-else-if ladder is used to check multiple conditions one after another.

When one condition becomes true, its block of code is executed, and the remaining conditions are skipped.

Example:

if (marks >= 90) {

    System.out.println("Grade A");

} else if (marks >= 75) {

    System.out.println("Grade B");

} else {

    System.out.println("Grade C");

}

Post a Comment

0 Comments