C++  .NET  C#  Java  C  ASP  HTML  Prolog  Visual Basic  Javascript  JScript  VBScript  MFC  Perl  PHP  Basic  Python  C  Assembler  VB  Ada  Ruby  XML  ASP.NET  C++  Java
[warebiz] :: Programming Bizness

Specializing in programming tutorials that make sense!

 Programming Tutorials

 Resources     » Articles
    » Projects
    » CS Dictionary
    » References
    » Books

 Site     » Home
    » About
    » Support
    » Make Donation
binary digits
C++ Ripped Apart Tutorial
Section 2: Controlling Execution With Control Structures 

You are in Section 2 of 9, Article 2.2 of 2.6, Part 2.2.1 of 2.2.3

2 .. Controlling Execution With Control Structures
       2.2 .. Selection Statements
              2.2.1 .. One-Way Decisions


There are generally three versions of selection statements to cover:

  • one-way
  • two-way
  • multi-way

One-way decision statements do some particular thing or they do nothing. Two-way decision statements do one thing or do another. Multi-way decision statements can do many different things depending on the result of an expression.

One-Way Decisions
One-way decisions are handled with an "if statement" and either do some particular thing or do nothing at all. The decision is based on a logical expression which either evaluates to true or false, a value of 1 or a value of 0, respectively.

It is important to remember that logical expressions always evaluate to a value of true or false; a nonzero value is always true, and a value of zero is always false.

If the logical expression is evaluated to true, then the corresponding statement is executed; if the logical expression evaluates to false, control goes to the next executable statement.

The form of a one-way decision statement is as follows:



The stmtT can be a simple or compound statement. Simple involves a single statement. Compound involves one or more statements enclosed with curly braces { }. A compound statement is called a block statement.

Example 1: simple statement



Example 2: compound statement



For an example of how one-way decision statements can be used in a program, consider the following complete program:

Source Code

1wayselection.cpp


Another type of selection statement is the two-way decision statement. Read on for more...

Next: Two-Way Decisions

You are in Section 2 of 9, Article 2.2 of 2.6, Part 2.2.1 of 2.2.3

[Back to Top]

Google
 
Web warebizprogramming.com

.: Report Bug : Error Log : About Webmaster :.

Search Warebiz!
binary digits binary digits

 Random Insight ::

binary digits

 Book References ::

binary digits
 C++  .NET  C#  Java  C  ASP  HTML  Prolog  Visual Basic  Javascript  JScript  VBScript  MFC  Perl  PHP  Basic  Python  C  Assembler  VB  Ada  Ruby  XML  ASP.NET  C++  Java