Why our notes

Built for Fast, Smart Revision

Everything is designed to save your time and lift your score.

✂️

Zero Fluff Summaries

Only exam-relevant points in short, crisp lines, so every minute of study counts.

🗺️

Flowcharts & Visual Timelines

Mind maps, flowcharts and timelines turn heavy topics into pictures you remember.

🎯

PYQ-Linked Key Points

Key points are linked to previous-year question trends so you know what matters most.

📱

Accessible on All Devices

Read on phone, tablet or laptop, or print a clean copy with the print-friendly layout.

Free Study Articles & Updates

UNIT 3 : Flow Control Structures Notes BCA Semester -1

UNIT 3 : Flow Control Structures

UNIT 3 : Flow Control Structures

 


Flow control structures in C programming empower you to manage the sequence of actions in your program based on conditions or repetition. The three primary control structures in C are:


1. Conditional (if-else) Statements:

   These are employed to execute a block of code only when a specific condition is satisfied.


   Example:


   ```c

   int x = 10;

   if (x > 5) {

       printf("x is greater than 5");

   }

   ```


2. Loops:

   Used to iteratively execute a block of code until a particular condition is met.


   Example:


   ```c

   for (int i = 0; i < 10; i++) {

       printf("%d\n", i);

   }

   ```


3. Switch Statements:

   These allow you to choose one block of code from multiple options based on the value of an expression.


   Example:


   ```c

   char grade = 'B';

   switch (grade) {

       case 'A':

           printf("Excellent!");

           break;

       case 'B':

           printf("Good!");

           break;

       case 'C':

           printf("Average");

           break;

       default:

           printf("Invalid grade");

   }

   ```


Decision Making Structures:


Decision-making structures in C are employed to make choices in a program based on certain conditions. There are two main decision-making structures:


1. if Statement:

   Used to execute a block of code only if a specified condition is true.


   Example:


   ```c

   int x = 10;

   if (x > 5) {

       printf("x is greater than 5");

   }

   ```


2. if-else Statement:

   Allows execution of one block of code if a condition is met and another if the condition is not met.


   Example:


   ```c

   int x = 10;

   if (x > 5) {

       printf("x is greater than 5");

   } else {

       printf("x is not greater than 5");

   }

   ```


Loop Control Structures:


Loop control structures in C are utilized to repetitively execute code until a certain condition is satisfied. The three primary loop control structures are:


1. for Loop:

   Used to execute a block of code a specific number of times.


   Example:


   ```c

   for (int i = 0; i < 10; i++) {

       printf("%d\n", i);

   }

   ```


2. while Loop:

   Executes a block of code as long as a specified condition is true.


   Example:


   ```c

   int i = 0;

   while (i < 10) {

       printf("%d\n", i);

       i++;

   }

   ```


3. do-while Loop:

   Similar to the while loop but ensures that the code inside the loop is executed at least once.


   Example:


   ```c

   int i = 0;

   do {

       printf("%d\n", i);

       i++;

   } while (i < 10);

   ```


Nested Control Structures:


Nested if-else and nested for loop structures enable testing multiple conditions and running inner loops for each iteration of an outer loop.


Example:


```c

int x = 10, y = 20;

if (x > 5) {

    if (y > 15) {

        printf("x is greater than 5 and y is greater than 15");

    } else {

        printf("x is greater than 5 and y is not greater than 15");

    }

} else {

    printf("x is not greater than 5");

}

```


Break, Continue, Goto, Exit:


These statements provide control over the flow of a program.


- break: Exits a loop prematurely.


  Example:


  ```c

  for (int i = 0; i < 10; i++) {

      if (i == 5) {

          break;

      }

      printf("%d\n", i);

  }

  ```


- continue:Skips the current iteration of a loop and proceeds to the next.


  Example:


  ```c

  for (int i = 0; i < 10; i++) {

      if (i % 2 == 0) {

          continue;

      }

      printf("%d\n", i);

  }

  ```


- goto: Jumps to a labeled statement in the program.


  Example:


  ```c

  for (int i = 0; i < 10; i++) {

      if (i == 5) {

          goto end;

      }

      printf("%d\n", i);

  }

  

  end:

      printf("Reached end of program.\n");

  ```


- exit: Immediately exits a program with a status value.


  Example:


  ```c

  for (int i = 0; i < 10; i++) {

      if (i == 5) {

          exit(0);

      }

      printf("%d\n", i);

  }

  ```

✍

Thanks for reading. Share this with a friend who is preparing too.

Comments

Want the complete course?Get full notes, tests and expert support.Browse Premium Courses
Simple & easy

How It Works

Get your notes in three easy steps.

1

Pick your exam

Choose UPSC, SSC, Banking, Railways, State PSC or Defence and find the subject you need.

2

Preview a free sample

Flip through sample pages with Quick Look before you decide to buy.

3

Buy and download the PDF

Pay securely and download your notes to read or print on any device.

FAQ

Frequently Asked Questions

How do I download the notes after buying?

After your payment is complete you receive a download link for the PDF. Open it on any device and save the file for offline reading.

Can I print the PDF notes?

Yes. The notes use a print-friendly layout with clean margins, so you can print the pages you need or the full notes.

How often are the notes updated?

Notes are reviewed for each exam cycle and pattern change. The latest status is shown on every product card, for example Updated Pattern.

Can I see a sample before I buy?

Yes. Every notes pack has a free sample. Click Free Sample (PDF) or Quick Look to flip through sample pages before you pay.

Which devices can I use to read the notes?

The notes are PDF files that open on mobiles, tablets, laptops and desktops with any free PDF reader.

Are the notes available in Hindi and English?

The language of each pack is shown on its card. Use the search box to find notes in the language you prefer.