Problem Solving Through C Unit 04 Conditional Statements and Loops Notes Set 01

Computer Science Study Guide: Problem Solving Through C Unit 04 Conditional Statements and Loops Notes Set 01

Review targeted academic resources with the Problem Solving Through C Unit 04 Conditional Statements and Loops Notes Set 01. Built according to official standards for the 2026-27 term, these downloadable Computer Science study materials support effective daily practice and deeper conceptual understanding for Programming in C.

Download Programming in C Study Material PDF

View or download the dedicated Problem Solving Through C Unit 04 Conditional Statements and Loops Notes Set 01 resource below. Engaging with these advanced study guides under focused conditions ensures continuous academic progress and mastery of the 2026-27 curriculum for Programming in C.

This page covers decision making in C: relational and logical operators, the if and if-else statements, and the while, for and do...while loops, including nested and infinite loops. It also explains the switch, break, continue and goto statements, and closes with structured programming, modular design and the sequence, selection and repetition constructs.

Decision Making within a Program - What is Decision making?

Decision making is the thoughtful consideration and selection of a course of action from among available alternatives in order to produce a desired result.

Most control statements in any computer language, including C, rely upon a conditional test that determines a course of action.

The conditional test either evaluates to a true or a false.

The concept of evaluating and obtaining a result is referred to as decision making in a programming language.

"True" is considered the same as "yes," which is also considered the same as 1.

"False" is considered the same as "no," which is considered the same as 0.

Decision Making and Conditions

Decision making structures require that the programmer specify one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to be false.

Following is the general form of a typical decision making structure found in most of the programming languages.

C programming language assumes any non-zero and non-null values as true, and if it is either zero or null, then it is assumed as false value.

C programming language provides following types of decision making statements.

Decision is a word which is normally taken in a moment where one is in a position to select one option from the available options which are obviously more than one.

While writing programs this concept is always going to play an important role.

We will have to provide the capabilities to our program so that it can take decisions on its own depending upon the various possible inputs from the user.

When you are going to write some program it will be always necessary that you will have to put some code which has to be executed only when a specific condition is satisfied.

These conditions are evaluated by the computer itself when the input is given by the user.

In C language there are various methods which can be used to select an appropriate set of statements depending upon the user's input.

On counting them, totally there are FOUR different ways to take decisions which are as follows :

if Statement.

if-else Statement.

Conditional Operators.

Switch Statement.

The Relational and Logical Operator

The relational operators are used to compare expressions, asking questions such as, "Is y greater than 100?" or "Is z equal to 0?"

An expression containing a relational operator evaluates to either true (1) or false (0).

"True" is considered the same as "yes," which is also considered the same as 1.

"False" is considered the same as "no," which is considered the same as 0.

An expression created using a relational operator forms what is known as a relational expression or a condition.

C's relational operators are as follows.

OperatorMeaning
<Less than
<=Less than or equal to
>Greater than
>=Greater than or equal to
==Equal to
!=Not equal to

Logical Operators

Logical operators let the user's combine two or more relational expressions into a single expression that evaluates to either true or false.

Logical operators consists of AND, OR and NOT as shown in the table below.

An expression containing a Logical operator evaluates to either true (1) or false (0).

"True" is considered the same as "yes," which is also considered the same as 1.

"False" is considered the same as "no," which is considered the same as 0.

OperatorMeaning
&&Logical AND
||Logical OR
!Logical NOT

Control Statement

If statement

A program control statement modifies the order of statement execution.

Program control statements can cause other program statements to execute multiple times or not to execute at all, depending on the circumstances.

The 'if' statement is one of the C's program control statements.

In its basic form, the 'if' statement evaluates an expression and directs program execution depending on the result of the evaluation.

If expression evaluates to true, statement is executed.

If statement evaluates to false, statement is not executed.

In either case, execution then passes to whatever code follows the 'if' statement.

The execution of statement depends on the result of expression.

The line if (expression) and the line statement; are considered to comprise the complete if statement; they are not separate statements.

An 'if' statement can control the execution of multiple statements through the use of a compound statement, or block.

A block is a group of two or more statements enclosed in braces.

A block can be used anywhere a single statement can be used.

Listed below is the syntax for if statement:

This is the 'if' statement in its simplest form.

If expression is true, statement1 is executed. If expression is not true, statement1 is ignored.

If statement Syntax

if (condition)
{
    //Block of C statements here
    //The above statements will only execute if the condition is true
}

If statement: Example

#include <stdio.h>
int main()
{
    int x = 20;
    int y = 22;
    if (x < y)
    {
        printf("Variable x is less than y");
    }
    return 0;
}

Output:
Variable x is less than y

Else Statement

An 'if' statement can optionally include an else clause.

The else clause is included as shown below:

If expression evaluates to true, statement1 is executed.

If expression evaluates to false, statement2 is executed.

Both statement1 and statement2 can be compound statements or blocks.

Figure (described): the test expression is checked; if true the body of if runs, otherwise the body of else runs, and execution then continues after the statement.

If-else Statement

The combination of the 'if' and else clause is called the 'if-else' statement.

This is the most common form of the 'if' statement.

If expression is true, statement1 is executed; otherwise, statement2 is executed.

This is a nested if.

If the first expression, expression1, is true, statement1 is executed before the program continues with the next statement.

If the first expression is not true, the second expression, expression2, is checked.

If the first expression is not true, and the second is true, statement2 is executed.

If both expressions are false, statement3 is executed.

Only one of the three statements is executed.

If-else statement Syntax

if (condition)
{
    /*Control will come inside only when the above condition is true*/
    //C statement(s)
}
else
{
    /*Control will come inside only when condition is false */
    //C statement(s)
}

If-else statement: Example

if (num > 10)
    printf("num is greater than 10");
else
    printf("num is less than or equal to 10");

Loops

There may be a situation, when you need to execute a block of code several numbers of times.

In general, statements are executed sequentially.

The first statement in a function is executed first, followed by the second, and so on.

Programming languages provide various control structures that allow for more complicated execution paths.

A loop statement allows us to execute a statement or group of statements multiple times and following is the general form of a loop statement in most of the programming languages.

C programming language provides the following types of loop to handle looping requirements.

while loop.

for loop.

do...while loop.

While loop - While Statement

The 'while' statement, also called the while loop, executes a block of statements as long as a specified condition is true.

The while statement has the following form:

while (condition)
    statement;

Condition is any C expression, and statement is a single or compound C statement.

When program execution reaches a while statement, the following events occur:

The expression condition is evaluated.

If condition evaluates to false (that is, zero), the while statement terminates, and execution passes to the first statement following the while statement.

If condition evaluates to true (that is, nonzero), the C statement(s) in statement are executed.

Execution returns to step 1.

while loop: Syntax

while (condition test)
{
    // C- statements, which requires repetition.
    // Increment (++) or Decrement (--) Operation.
}

while loop: Example

main()
{
    int count=1;
    while (count<=4)
    {
        printf("%d ", count);
        count++;
    }
}

For loop - Introduction

The 'for' statement is a C programming construct that executes a block of one or more statements a certain number of times.

It is sometimes called the 'for' loop because program execution typically loops through the statement more than once.

A for statement has the following structure:

for (initial; condition; increment)
    statement;

Initial, condition, and increment are all C expressions, and statement is a single or compound C statement.

The 'for' Statement

When a 'for' statement is encountered during program execution, the following events occur:

The expression initial is evaluated. Initial is usually an assignment statement that sets a variable to a particular value.

The expression condition is evaluated; condition is typically a relational expression.

If condition evaluates to false (that is, as zero), the 'for' statement terminates, and execution passes to the first statement following the for statement.

If condition evaluates to true (that is, as nonzero), the C statement(s) in statement are executed.

The expression increment is evaluated, and execution returns to the expression condition.

for loop: Syntax

for (initialization; condition test; increment or decrement)
{
    //Code - C statements needs to be repeated
}

for loop: Example

int i;
for (i=1; i<=3; i++)
{
    printf("hello, World");
}

The do...while Loop

C's third loop construct is the 'do...while' loop, which executes a block of statements as long as a specified condition is true.

The do...while loop tests the condition at the end of the loop rather than at the beginning, as is done by the 'for' loop and the while loop.

The structure of the do...while loop is as follows:

do
    statement;
while (condition);

Condition is any C expression, and statement is a single or compound C statement.

When program execution reaches a do...while statement, the following events occur:

Step 1:The statements in statement are executed.

Step 2:Condition is evaluated.

Step 3:If it's true, execution returns to step 1.

Step 4:If it's false, the loop terminates.

The statements associated with a do...while loop are always executed at least once.

This is because the test condition is evaluated at the end, instead of beginning, of the loop.

In contrast, for loops and while loops evaluate the test condition at the start of the loop, so the associated statements are not executed at all if the test condition is initially false.

The do...while loop is used less frequently than while and for loops.

It is most appropriate when the statement(s) associated with the loop must be executed at least once.

The user could, of course, accomplish the same thing with a while loop by making sure that the test condition is true when execution first reaches the loop.

do...while loop: Syntax

do
{
    //C- statements
} while (condition test);

do...while loop: Example

main()
{
    int i=0;
    do
    {
        printf("while vs do-while\n");
    } while (i==1);
    printf("Out of loop");
}

Nested Loop - Introduction

A nested loop is a loop within a loop, an inner loop within the body of an outer one.

It has the following structure:

Figure (described): an outer loop condition; while it is true the inner loop condition is tested, and while that is true the inner loop body runs and control returns to the inner test; when the inner test is false control returns to the outer test, and when the outer test is false the loops end.

What happens is that the first pass of the outer loop triggers the inner loop, which executes to completion.

Then the second pass of the outer loop triggers the inner loop again.

This repeats until the outer loop finishes.

Of course, a break within either the inner or outer loop may interrupt this process.

When the user "nest" two loops, the outer loop takes control of the number of complete repetitions of the inner loop.

While all types of loops may be nested, the most commonly nested loops are for loops.

Example

main()
{
    for (int i=0; i<=10; i++)
    {
        for (int j=0; j<=10; j++)
        {
            printf("%d, %d", i, j);
        }
    }
}

Infinite Loop

An 'infinite' loop is a loop that never terminates.

When the condition that controls the loop execution never becomes false, the loop can never stop executing.

One such example is shown below:

Figure (described): a flowchart that sets ctr = 0 and A = 0, adds 1 to ctr, tests A > ctr (never true because A stays 0), prints ctr and loops back, so the loop never stops.

One creates an infinite loop.

The condition that the while tests is the constant 1, which is always true and can't be changed by the program.

Because 1 can never be changed on its own, the loop never terminates.

One can also create an infinite loop with the for-statement:

Switch Statement

C's most flexible program control statement is the switch statement, which lets the program execute different statements based on an expression that can have more than two values.

Earlier control statements, such as if, were limited to evaluating an expression that could have only two values:

True or false.

To control program flow based on more than two values, the user had to use multiple nested if statements.

Its purpose is to allow the value of a variable or expression to control the flow of program execution.

A switch statement is defined across many individual statements.

Switch Case

switch(expression)
{
    case constant1:
        statements 1;
        break;
    case constant2:
        statements 2;
        break;
    ...
    default:
        statements n;
        break;
}

The structure of switch case is as shown below:

Figure (described): each case test (T) runs its statements and then a break that jumps past the switch; a false test (F) moves to the next case, and the default statements run when no case matches.

From the statement, expression is any expression that evaluates to an integer value: type long, int, or char.

The switch statement evaluates expression and compares the value against the templates following each case label, and then one of the following happens:

If a match is found between expression and one of the templates, execution is transferred to the statement that follows the case label.

If no match is found, execution is transferred to the statement following the optional default label.

If no match is found and there is no default label, execution passes to the first statement following the switch statement's closing brace.

switch case: Example

int main()
{
    int num=2;
    switch(num+2)
    {
        case 1:
            printf("Case1: Value is: %d", num);
        case 2:
            printf("Case1: Value is: %d", num);
        case 3:
            printf("Case1: Value is: %d", num);
        default:
            printf("Default: Value is: %d", num);
    }
    return 0;
}

Break Statement

The break statement can be placed only in the body of a 'for' loop, 'while' loop, or 'do...while' loop.

Figure (described): a test condition inside the loop; when it is true, break jumps out of the loop, otherwise the loop continues.

When a break statement is encountered, execution exits the loop.

int main()
{
    int i;
    clrscr();
    for (i=1; i<=10; i=i+1)
    {
        if (i==2)
            break;
        printf("%d\n", i);
    }
    while (i<=10)
    {
        if (i==4)
            break;
        printf("%d\n", i);
        i=i+1;
    }
    do
    {
        if (i==6)
            break;
        printf("%d\n", i);
        i=i+1;
    } while (i<=10);
    getch();
    return 0;
}

From the example, left to itself, the 'for' loop would execute 10 times.

On the sixth iteration, however, count is equal to 5, and the break statement executes, causing the 'for' loop to terminate.

Execution then passes to the statement immediately following the for loop's closing brace.

When a break statement is encountered inside a nested loop, it causes the program to exit the innermost loop only.

for (initialization; condition; increment)
{
    Statement 1;
    Statement 2;
    Statement 3;
    ...
    break;       /* control jumps to Outside Statement 1 */
    Statement N-1;
    Statement N;
}
Outside Statement 1;

The break statement ends the loop and moves control to the next statement outside the loop.

The break statement ends only the smallest enclosing do, for, switch, or while statement.

The break statement in C programming language has the following two usages:

When the break statement is encountered inside a loop, the loop is immediately terminated and program control resumes at the next statement following the loop.

It can be used to terminate a case in the switch statement.

Continue Statement

Like the break statement, the continue statement can be placed only in the body of a 'for' loop, a while loop, or a 'do...while' loop.

Figure (described): when the test condition inside the for loop is true, continue skips the remaining part of the loop and goes back to the loop test; otherwise the remaining part of the loop runs normally.

When a continue statement executes, the next iteration of the enclosing loop begins immediately.

The statements between the continue statement and the end of the loop aren't executed

Continue;

Continue is used inside a loop.

It causes the control of a program to skip the rest of the current iteration of a loop and start the next iteration.

The following is an example for the continue statement.

Example

for (int j=0; j<=8; j++)
{
    if (j==4)
    {
        continue;
    }
    printf("%d ", j);
}

Goto Statement

The goto statement is one of C's unconditional jump, or branching statements.

Figure (described): statements labelled label 1, label 2 and label 3 run in order, but a goto label 3 skips statement 2 and jumps directly to statement 3.

When program execution reaches a goto statement, execution immediately jumps, or branches, to the location specified by the goto statement.

This statement is unconditional because execution always branches when a goto statement is encountered; the branch doesn't depend on any program conditions.

A goto statement and its target must be in the same function, but they can be in different blocks.

Often, a break statement, a continue statement, or a function call can eliminate the need for a goto statement.

Goto Statement: Example

int main()
{
    int age;
Vote:
    printf("you are eligible for voting");
NoVote:
    printf("you are not eligible to vote");

    printf("Enter you age:");
    scanf("%d", &age);
    if (age>=18)
        goto Vote;
    else
        goto NoVote;

    return 0;
}

Structured Programming

Structured programming is a methodology that is part of a renewed emphasis on software engineering, which involves the systematic design and development of software and the management of the software development process.

Software engineering views the development of a program as a coordinated activity involving people, tools, and practices; use of modern design; and development and management methods in an integrated approach.

Structured approach involves the use of methods such as top-down program design and a limited number of control structures in a program to create tightly structured modules of program code.

The effect of top-down design and structured programming has been used to lower the overall cost of programming.

The structured approach promises to reduce the cost of developing and maintaining computer programs by standardizing program development and structures used.

This increases the simplicity and accuracy, and at the same time minimizes programming and maintenance cost.

A 'traditional' flexible and creative environment provided to the programmer often results in complex and difficult-to-read programs requiring much testing before they are error-free.

These also become costly to develop and maintain.

Structured programming, on the other hand, emphasizes group responsibility for program development.

It also brings in a standardization of program-design concepts and methods, which significantly reduces the program complexity.

Organizations using structured programming have shown the following characteristics:

Programming Productivity: Programmers write more program statements per day with fewer errors.

Program Economy: The cost and time of program development and maintenance are reduced.

Program Simplicity: Programs are easier to read, write, correct, and maintain.

These results highlight the reasons for structured programming to continue to be a popular programming methodology.

Modular Design

Structured programming is used as a set of tools to improve program organization, facilitate problem solving, and make code easier to write and analyses in both individual and group projects.

Using structured programming, the solution to the problem is divided into segments called modules.

A module is a logically separable part of a program.

It is a unit, discrete and identifiable with respect to compilation and loading.

In terms of common programming language constructs, a module can be a macro, a function, a procedure (or subroutine), a process, or a package.

Each module involves processing of data that are logically related. Modules are functional parts that aid in processing.

Ideally, each module works independent of other modules, although this is sometimes impossible.

Modules are ranked by hierarchy and organized on the basis of importance.

The lower the module on the structure organization plan, more is the detail given to the programming steps involved.

The controlling module resides at the top level.

It gives the view of the overall structure for the entire program.

The system is designed to give more detail at each module level.

A module is coded and tested, and then tested with other tested modules.

This procedure makes program testing easier, since there is only one entry point and one exit point per module.

C is called a structured programming language because to solve a large problem, C programming language divides the individual small responsibilities to smaller modules called functions or procedures.

One major drawback of C language is that similar functions cannot be grouped inside a module or class.

Also functions cannot be associated to a type or structure thus data and functions cannot be bound together.

Structured Programming Constructs

The most common techniques used in structured programming to solve all problems are called constructs.

Sequence, selection, and repetition

These constructs are also called control structures.

Using these three basic control structures, it is possible to write standardized programs, which are easy to read and understand.

Sequence Structure

Sequence refers to an instruction or a series of instructions that perform a required calculation or allow input or output of data.

Since these steps are executed one after the other, there is no change in the flow logic.

Figure (described): Entry leads to Module A, then Module B, then Module C, then Exit.

The picture illustrates that program statements in function A will be executed before those for function B.

In other words, we say that control 'flows' from function A to function B.

Selection Structure

Selection refers to testing for a certain condition for data.

There are only two possible answers to questions regarding data - true (yes) or false (no).

One selection-technique variation is known as the IF-THEN-ELSE.

The instructions that are to be executed when the condition is true follow the IF-THEN alternative.

The instructions followed by the ELSE alternative represent what is to be executed when the condition is false.

If the condition is true, the control will flow to function B and its statements will be executed; if it is false, function A is executed.

Repetition Structure

Repetition involves the use of a series of instructions that are repeated until a certain condition is met.

Repetition involves the use of two variations - the for, while and the do-while.

The while performs a function as long as a condition is true.

On the other hand, do-while allows a function to be executed until the given condition is false.

Another marked difference is that the while first tests the given condition and then executes the function, whereas do-while processes the function before checking the condition.

Before writing a program to solve a particular problem, it's essential to have a thorough understanding of the problem and a carefully planned approach to solving the problem.

Control Structures

Normally, statements in a program are executed one after the other in the order in which they're written.

This is called sequential execution.

Various C statements we'll soon discuss enable the user to specify that the next statement to be executed may be other than the next one in sequence.

This is called transfer of control.

CBSE Computer Science Study Material: Programming in C

Quick Revision Material for Programming in C

Access comprehensive study material for Programming in C, including revision notes, concept maps, and high-probability questions. These resources are designed in alignment with the latest 2026 CBSE syllabus for Computer Science to support effective exam preparation.

Expert Notes and Solved Exam Questions

Designed around the official curriculum, these study guides guarantee standard compliance. Reviewing step-by-step solutions clarifies complex sub-topics within Programming in C and demystifies standard marking schemes for Computer Science evaluations.

Additional Study Resources for

Wrap up your chapter revision by testing your knowledge against standard objective question formats. Explore our full library of free, up-to-date sample papers and online assessments to secure top grades in your CBSE examinations.

FAQs

Where can I find the most advanced study material for [current-page:node:field_board] [current-page:node:field_class] Computer Science for 2026-27?

The latest 2026-27 advanced study resources for Computer Science are available for free on StudiesToday.com which includes NCERT Exemplars, high-order thinking skills (HOTS) questions, and deep-dive concept summaries.

What does the 2026-27 Computer Science study package for [current-page:node:field_class] include?

Our exhaustive Computer Science package includes chapter wise revision notes, solved practice sheets, important formulas and Concept Maps to help in better understanding of all topics.

Is this study material enough for both [current-page:node:field_board] exams and competitive tests?

Yes. For , our resources have been developed to help you get better marks in school exams and also build fundamental strength needed for entrance tests including Competency Based learning.

How should [current-page:node:field_class] students use this Computer Science material for maximum marks?

in , students should use Active Recall method, read the concept summary, then solve the Important Questions section without looking at the answers and then check your answers.

Can I download [current-page:node:field_class] Computer Science study notes in PDF for offline use?

All Computer Science study materials are provided in mobile-friendly PDF. You can download and save them on your device.

Are the [current-page:node:field_class] Computer Science resources updated for the latest NEP guidelines?

Yes, our team has ensured that all Computer Science materials for are strictly aligned with the National Education Policy (NEP) 2020 and the latest 2026-27 syllabus.