0

I got this paragraph from a Programming Language book:

Understanding selection statements:

Every application needs to be able to select from choices and branch along different code paths. The two selection statements in C# are if and switch. You can use if for all your code, but switch can simplify your code in some common scenarios such as when there is a single variable that can have multiple values that each require different processing.

Would anybody explain it to me that what does exactly the bold section say?

2 Answers 2

1

"to branch" comes from observing trees. The trunk grows in different paths. Then each branch grows in different paths. Then each of those branches grow in different paths, etc.

The term "branch" is widely applied to indicate divisions. For example, languages are said to have 3 main branches: Indo-European, Sino-Tibetan and Afro-Asiatic. Typically, these divisions are drawn as a diagram with more divisions -- i.e. branches -- below the main branches. Eventually 'English' will be shown as a branch. And, to further the tree analogy, the top of the chain of branches is called the root.

Coding uses "if" (choice) statements to "branch". For example, "IF color = red THEN stop ELSE go. Two choices: stop and go. Two branches. This can be drawn as a diagram. With many choices -- many branches -- the drawing begins to look like a tree. The paragraph given refers to "selection" because the program selects the branch based on the "if" condition. And "select a branch" is usually shortened to "branch" as a verb.

1
  • 1
    And "select a branch" is usually shortened to "branch" as a verb, this part was all that I needed to know. Thanks a lot bro. Jan 27 at 0:17
1

Without getting too into the coding technicals, "to branch" means to split, or to fork. Imagine a tree - a tree has branches, so it will split from the trunk into its different branches.

In the above paragraph, this means that a given application might make different choices, and proceed along different 'branches' -- in this case, meaning something like "parallel paths", where the user might make different choices.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .