Skip to main content Accessibility help
×
Hostname: page-component-6bb9c88b65-dwch4 Total loading time: 0 Render date: 2025-07-27T09:52:38.742Z Has data issue: false hasContentIssue false

9 - Branching Statement

Published online by Cambridge University Press:  17 July 2025

Subrata Saha
Affiliation:
Techno India Hooghly, West Bengal
Subhodip Mukherjee
Affiliation:
Techno India College of Technology, West Bengal
Get access

Summary

In the previous chapter we have learnt to write simple C programs. The statements in the programs are executed sequentially, i.e., one after another as they appeared in the program. However, in practice, the problems are not so simple. We need to take decision whether a particular set of statements will execute or not; instead of one group of statements another group of statements may execute; even group of statements may execute repeatedly for known number of times or until certain condition are met. Thus the order of execution of statements has to be controlled. The statements which control the order of execution is known as Control statement. There are two type of control statement in C. These are:

  • • Branching and

  • • Looping

Branching statement decides what actions to take and loop statement decides how many times to execute a certain action. In this chapter, we discuss on several branching statements.

Branching is so called because the program chooses to follow one branch or another. This type of statements is also known as conditional statement as depending on the condition a certain set of statement(s) executes. C has mainly two branching statements – if statement and switch statement.

IF STATEMENT

The most important branching statement is if statement. It handles one way as well as two way decision. The if statement consists of two parts – a test expression and one or more statements or block of statements. The decision is taken based on the expression given in parenthesis with the if statement. If the expression is true then a particular statement or block of statements gets executed.

Information

Type
Chapter
Information
Publisher: Cambridge University Press
Print publication year: 2016

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Book purchase

Temporarily unavailable

Accessibility standard: Unknown

Accessibility compliance for the PDF of this book is currently unknown and may be updated in the future.

Save book to Kindle

To save this book to your Kindle, first ensure no-reply@cambridge-org.demo.remotlog.com is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

Available formats
×

Save book to Dropbox

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.

Available formats
×

Save book to Google Drive

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.

Available formats
×