Expanding Conditional Statements

Assigning a Logical Expression to a Boolean Variable

A Boolean variable can be initialized with "true", or "false", or with a Boolean expression. This would be done as follows:

bool variable = operand1 Boolean-operator operand2;

To make your code easy to read, you should include the logical expression in parentheses. This can be done as follows:

bool variable = (operand1 Boolean-operator operand2);

A Conditional Statement in a Class

There are various ways you can create a conditional statement in an ASP.NET Core Web project. If you are working in a code file, simply write your code there (we will see examples if later lessons). Here is an example:

int number1;
int number2;

string result = "The second number is lower than the first number.";

if(number1 < number2)
    result = "The first number is lower than the second number.";

A Conditional Statement in a Razor Page Section

You can create a conditional statement inan @{} or an @functions{} section of a Razor Page. Here is an example:

@page
@model Operations.Pages.AdditionModel
@{    
    int number1 = 904_805;
    int number2 = 308_468;        
    string result = "The second number is lower than the first number.";
    
    if(number1 < number2)
        result = "The first number is lower than the second number.";
}

<form method="post" name="frmExercise">
    <table style="width: 300px">
        <tr>
            <td style="width: 150px">Number 1:</td>
            <td><input type="text" id="txtOperand1" name="txtOperand1"
                       value="@number1" style="width: 100px" /></td>
        </tr>
        <tr>
            <td>Number 2:</td>
            <td><input type="text" id="txtOperand2" name="txtOperand2"
                       value="@number2" style="width: 100px" /></td>
        </tr>
    </table>

    <p>@result</p>
</form>

Embedding a Conditional Statement in HTML

You can create a conditional statement in a section that contains HTML code. Although there are restrictions as we will see in various lessons, there are two primary rules:

  1. You must start the statement with @
  2. The statement must have a body delimited by curly brackets. Inside those curly brackets, you can write the HTML statement(s) that respond(s) to the conditional statement

Here is an example for a simple if conditional statement:

@page
@model Operations.Pages.AdditionModel
@{    
    int number1 = 308_468;
    int number2 = 904_805;    
}

<form method="post" name="frmExercise">
    <table style="width: 300px">
        <tr>
            <td style="width: 150px">Number 1:</td>
            <td><input type="text" id="txtOperand1" name="txtOperand1"
                       value="@number1" style="width: 100px" /></td>
        </tr>
        <tr>
            <td>Number 2:</td>
            <td><input type="text" id="txtOperand2" name="txtOperand2"
                       value="@number2" style="width: 100px" /></td>
        </tr>
    </table>

    @if( number1 < number2)
    {
        <p>"The first number is lower than the second number.";result</p>
    }
</form>

What Else?

Introduction

To consider an alternative to an if condition, you can use the else keyword, as in:

@{
    if(condition)
        statement1;
    else
        statement2;
}

If the condition is true, then the statement1 would execute. If the condition is false, then the compiler would execute the statement2 in the else section. Here is an example:

@{
    int number = 248;
    string result = "";

    if(number == 248)
        result = "That number is correct.";
    else
        result = "That number is not right.";
}

<p>@result</p>

This would produce:

That number is correct.

The Ternary Operator (?:)

We have seen that an if...else conditional statement can be performed. Here is an example:

@{
    double value;
    string choice = "Residential";

    if(choice == "Residential")
        value = 16.55;
    else
        value = 19.25;
}

<pre>Account Type: Residential
Value:        @value</pre>

If you have a condition that can be checked as an if situation with one alternate else, you can use the ternary operator. Here is an example:

@{
    string choice = "Residential";

    double value = (choice == "Residential") ? 16.55 : 19.25;
}

<pre>Account Type: Residential
Value:        @value</pre>

If...Else If

An if...else conditional statement processes only one situation. If you are dealing with more than two conditions, you can use an if...else if condition, as in:

if(condition1) statement1;
else if(condition2) statement2;

In some cases, such as when writing your code in a Razor Page, you can or must add a body delimited by curly brackets, as follows:

if(condition1) {
    statement1;
}
else if(condition2) {
    statement2;
}

If... Else If... Else

Because there can be other alternatives, you can add more else conditions, as in:

if(condition1)
    statement1;
else if(condition2)
    statement2;
else
    statement-n;

In some cases, you can add a body delimited by curly brackets to any of the conditions:

if(condition1){
    statement1;
}
else if(condition2) {
    statement2;
}
else {
    statement-n;
}

If...Else If ... Else If and Else

The if...else conditional statement allows you to process many conditions, as in:

if(condition1) statement1;
else if(condition2) statement2;
. . .
else if(condition_n) statement_n;

If you are writing the code in a webpage, each statement must be included in curly brackets. The formula to follow is:

@{
    if(condition1) { statement1; }
    else if(condition2) { statement2; }
    . . .
    else if(condition_n) { statement_n; }
}

If there is a possibility that none of the conditions would respond true, you can add a last else condition and its statement, as in:

if(condition1)
    statement1;
else if(condition2)
    statement2;
. . .
else if(condition_n)
    statement_n;
else
    statement-n;

In a webpage, the formula to follow is:

@{
    if(condition1) {
        statement1;
    }
    else if(condition2) {
        statement2;
    }
    . . .
    else if(condition_n) {
        statement_n;
    }
    else {
        statement-n;
    }
}

Going To a Statement

To jump from one statement or line to another, you can use the goto operator.

Boolean Conjunctions

Nesting a Conditional Statement

You can create a conditional statement in the body of another conditional statement. This is referred to as nesting the condition. This can be done as follows:

if( condition1 )
    if( condition2 )
    	statement(s)

In some cases, you can or must use curly brackets, as in:

if( condition1 )
{    
    if( condition2 )
    {
        statement(s)
    }
}

In the same way, you can nest a condition that itself is nested in anotherchild code in curly brackets:

if( condition1 )
{    
    if( condition2 )
    {    
        if( condition3 )
	{
            statement(s)
        }
    }
}

A Logical Binary Conjunction

A Boolean conjunction consists of combining two conditions. This can be done with the logical operator represented by the & operator, as in:

condition1 & condition2

A Conditional Binary Conjunction

An alternative is to use the && operator, as in:

condition1 && condition2

In both cases (the & and the && operations), the compiler first checks the first condition. If that first condition is false, the whole statement is false. In that case also, if you are using the && operator, the compiler doesn't check the second condition; but you are using the & operator, the compiler checks the second condition anyway. Either way, a Boolean conjunction produces a true result only if both conditions are true. Here is an example:

@page
@model Valuable.Pages.ExerciseModel

@{
    int degree = 1;
    bool security = true;
    string strDecision = "";

    if( degree == 1 & security == true )
        strDecision = "Welcome on board.";
    else
        strDecision = "We will get back to you...";
}

<h3>Employment Application</h3>
<hr />
<p>Employment Decision: @strDecision</p>

This would produce:

Employment Application

Employment Decision: Welcome on board.

It is a good idea to put each condition in its own parenthesis. Here are examples:

@page
@model Valuable.Pages.FormattingValuesModel

@{
    int degree = 1;
    bool security = true;
    string strDecision = "";

    if( (degree == 1) && (security == true) )
        strDecision = "Welcome on board.";
    else
        strDecision = "We will get back to you...";
}

<h3>Employment Application</h3>
<hr />
<p>Employment Decision: @strDecision</p>

A Conjunction for Non-Equivalence

Remember that if a condition is using the <, the <=, the >, or the >=, you can use "is <", "is <=", "is >", or "is >=" operators respectively. Here is an example:

@page
@model Valuable.Pages.FormattingValuesModel

@{
    int level = 3;
    string strDecision = "";

    if( level is >= 2 && level is <= 4 )
        strDecision = "Welcome on board.";
    else
        strDecision = "We will get back to you...";
}

<h3>Employment Application</h3>
<hr />
<pre>To grant you this job, we need to ask a few questions.
Levels of Security Clearance:
0. Unknown or None
1. Non-Sensitive
2. National Security - Non-Critical Sensitive
3. National Security - Critical Sensitive
4. National Security - Special Sensitive
----------------------------------------------------------------
Security Level: @level
Employment Decision: @strDecision</pre>

This would produce:

Employment Application

To grant you this job, we need to ask a few questions.
Levels of Security Clearance:
0. Unknown or None
1. Non-Sensitive
2. National Security - Non-Critical Sensitive
3. National Security - Critical Sensitive
4. National Security - Special Sensitive
----------------------------------------------------------------
Security Level: 3
Employment Decision: Welcome on board.

Additionally, you can use the and operator combined with the is operator.

Combining Conjunctions

If two conditions are not enough, you can create as many conjunctions as you want, as in:

condition1 & condition2 & condition3 & . . . & condition_n

or:

condition1 && condition2 && condition3 && . . . && condition_n

In this operation, if at least oneof the conditions is false, the whole operation is false. The only time the whole operation is true is if all the operations are true.

Boolean Disjunctions

A Logical Exclusion

A logical exclusion is a comparision that combines two conditional statements and uses an operator named XOR. It is performed with the ∧ operator as it:

condition1condition2

If the result of one of the operations (such as True) is the opposite of the other (such as False), the operation produces a True result. This means that if both both conditions produce the same type of result (that is, both are True or both are False), the result of the operation is False.

A Boolean Logical Disjunction

A logical disjunction combines two conditions to find out if at least one of those conditions produces a True result. To perform this operation, you can use the Boolean logical disjunction operator |, as in:

condition1 | condition2

The Conditional Logical Disjunction

The conditional logical disjunction is performs a comparison with the same goal as the Boolean Logical Disjunction. Is uses the || operator, as in:

condition1 || condition2

In both cases, the first condition is first checked. If the first condition is True, if you are using the || operator, the second condition is not checked. In either case, the operation produces a True result. If you are using the | operator, the second condition is checked any way. If the first condition is False, if you are using the || operator, then the second condition is checked (remember that, with the | operation, the compiler checks the second condition regardless of the result of the first condition). If the second condition is True, the whole operation produces a True result. This means that if either condition is True, the operation is True. Both conditions are False, the whole operation produces a False result.

A Disjunction for Non-Equivalence

When a condition is formulated with the <, the <=, the >, or the >= operator, to make your code easy to read, you can use the or operator. It is combined with the is operator. The formula to follow is:

operand is condition1 or condition2

Here is an example:

@page
@model Valuable.Pages.ExerciseModel

@{
    int security = 3;
    int education = 3;
    string strDecision = "";
    
    if( security is >= 2 or > 3 )
        strDecision = "Congratulations: Welcome on board.";
    else
        strDecision = "Well... We will get back to you...";
}

<h3>Employment Application</h3>
<hr />
<pre>Job Requirements Evaluation
======================================================
Levels of Security Clearance:
0. Unknown or None
1. Non-Sensitive
2. National Security - Non-Critical Sensitive
3. National Security - Critical Sensitive
4. National Security - Special Sensitive
------------------------------------------------------
Levels of Education:
1. Kindergarten or Elementary School
2. High School
3. Some College or Associate Degree
4. Bachelor's Degree
5. Graduate Degree
======================================================
Candidate's Evaluation:
Level of Security Clearance: @security
Level of Education: @education
------------------------------------------------------
Decision: @strDecision
======================================================</pre>

This would produce:

Employment Application

Job Requirements Evaluation
======================================================
Levels of Security Clearance:
0. Unknown or None
1. Non-Sensitive
2. National Security - Non-Critical Sensitive
3. National Security - Critical Sensitive
4. National Security - Special Sensitive
------------------------------------------------------
Levels of Education:
1. Kindergarten or Elementary School
2. High School
3. Some College or Associate Degree
4. Bachelor's Degree
5. Graduate Degree
======================================================
Candidate's Evaluation:
Level of Security Clearance: 3
Level of Education: 3
------------------------------------------------------
Decision: Congratulations: Welcome on board.
======================================================

To make your code easy to read, you can include each condition in its own parentheses. This can be done as follows:

@page
@model Valuable.Pages.ExerciseModel

@{
    int security = 1;
    int education = 4;
    string strDecision = "";
    
    if( security is (>= 2) or (> 3) )
        strDecision = "Congratulations: Welcome on board.";
    else
        strDecision = "Well... We will get back to you...";
}

<h3>Employment Application</h3>
<hr />
<pre>Job Requirements Evaluation
======================================================
Levels of Security Clearance:
0. Unknown or None
1. Non-Sensitive
2. National Security - Non-Critical Sensitive
3. National Security - Critical Sensitive
4. National Security - Special Sensitive
------------------------------------------------------
Levels of Education:
1. Kindergarten or Elementary School
2. High School
3. Some College or Associate Degree
4. Bachelor's Degree
5. Graduate Degree
======================================================
Candidate's Evaluation:
Level of Security Clearance: @security
Level of Education: @education
------------------------------------------------------
Decision: @strDecision
======================================================</pre>

This would produce:

Employment Application

Job Requirements Evaluation
======================================================
Levels of Security Clearance:
0. Unknown or None
1. Non-Sensitive
2. National Security - Non-Critical Sensitive
3. National Security - Critical Sensitive
4. National Security - Special Sensitive
------------------------------------------------------
Levels of Education:
1. Kindergarten or Elementary School
2. High School
3. Some College or Associate Degree
4. Bachelor's Degree
5. Graduate Degree
======================================================
Candidate's Evaluation:
Level of Security Clearance: 1
Level of Education: 4
------------------------------------------------------
Decision: Well... We will get back to you...
======================================================

Combining Disjunctions

You can create a conditional statement that includes as many disjunctions as you want, as in:

condition1 | condition2 | . . . | condition_n

Or:

condition1 || condition2 || . . . || condition_n

Practical LearningPractical Learning: Starting a Project

  1. Start Microsoft Visual Studio
  2. In the Visual Studio 2022 dialog box, under Get Started, click Create a New Project
  3. In the large list on the right side of the dialog box, click ASP.NET Core Web App
  4. Click Next
  5. Change the Name to MachineDepreciation2
    Accept or change the Location
  6. In the Target Framework combo box, select the latest version (.NET 7.0 (Standard Term Support)).
  7. Remove the check mark on Configure For HTTPS
  8. Click Create
  9. In the Solution Explorer, expand wwwroot. Then right-click css -> Add -> New Item...
  10. In the left list of the Add New Item dialog box, under C#, expand ASP.NET Core, and expand Web. Then click Content
  11. In the middle list, click Style Sheet
  12. Change the file Name to MachineDepreciation
  13. Click Add
  14. Change the document as follows:
    body {
    }
    
    .ta-right    { text-align:          right;               }
    .ta-center   { text-align:          center;              }
    .delimiter   { margin:              auto;
                   width:               650px;               }
    .top-bar     { border-bottom:       6px solid blue;
                   background-color:    #f06d01 !important;  }
    .common-font { font-family:         Georgia, Garamond, 'Times New Roman', serif; }
    .navbar-light .navbar-brand       { color:       white;  }
    .navbar-light .navbar-brand:hover { color:       yellow; }
    .navbar-light .navbar-brand:focus { color:       khaki;  }
    .navbar-light .navbar-brand       { font-family: Georgia, Garamond, 'Times New Roman', serif; }
    .nav-link                         { font-family: Georgia, Garamond, 'Times New Roman', serif; }
  15. In the Solution Explorer, right-click Pages -> Add -> Razor Page...
  16. In the Add New Scaffolded Item dialog box, make sure Razor Page - Empty is selected.
    Click Add
  17. Change the file Name to StraightLineMethod
  18. Click Add

Practical LearningPractical Learning: Embedding a Conditional Statement

  1. Change the document as follows:
    @page
    @model StraightLineMethod.Pages.DepreciationModel
    @using static System.Console
    @{
        int year = 0;
        int estimatedLife = 0;
        double machineCost = 0.00;
        double salvageValue = 0.00;
        double depreciationRate = 0.00;
        double yearlyDepreciation = 0.00;
        string strDepreciation12 = string.Empty;
        string strDepreciationRate = string.Empty;
        string strDepreciableAmount = string.Empty;
    
        double bookValueYear0 = 0.00;
        double bookValueYear1 = 0.00;
        double bookValueYear2 = 0.00;
        double bookValueYear3 = 0.00;
        double bookValueYear4 = 0.00;
        double bookValueYear5 = 0.00;
        double bookValueYear6 = 0.00;
        double bookValueYear7 = 0.00;
        double bookValueYear8 = 0.00;
        double bookValueYear9 = 0.00;
        double bookValueYear10 = 0.00;
    
        string strBookValueYear0 = "0.00";
        string strBookValueYear1 = "0.00";
        string strBookValueYear2 = "0.00";
        string strBookValueYear3 = "0.00";
        string strBookValueYear4 = "0.00";
        string strBookValueYear5 = "0.00";
        string strBookValueYear6 = "0.00";
        string strBookValueYear7 = "0.00";
        string strBookValueYear8 = "0.00";
        string strBookValueYear9 = "0.00";
        string strBookValueYear10 = "0.00";
    
        string strAccumulatedDepreciation1 = "0.00";
        string strAccumulatedDepreciation2 = "0.00";
        string strAccumulatedDepreciation3 = "0.00";
        string strAccumulatedDepreciation4 = "0.00";
        string strAccumulatedDepreciation5 = "0.00";
        string strAccumulatedDepreciation6 = "0.00";
        string strAccumulatedDepreciation7 = "0.00";
        string strAccumulatedDepreciation8 = "0.00";
        string strAccumulatedDepreciation9 = "0.00";
        string strAccumulatedDepreciation10 = "0.00";
    
        string strYearlyDepreciation = "0.00";
    
        if (Request.HasFormContentType)
        {
            machineCost = double.Parse(Request.Form["txtMachineCost"]!);
            salvageValue = double.Parse(Request.Form["txtSalvageValue"]!);
            estimatedLife = int.Parse(Request.Form["txtEstimatedLife"]!);
    
            depreciationRate = 100 / estimatedLife;
            yearlyDepreciation = (machineCost - salvageValue) / estimatedLife;
            strDepreciation12 = $"{(yearlyDepreciation / 12):n}";
    
            strYearlyDepreciation = $"{yearlyDepreciation:f}";
    
            bookValueYear0 = machineCost - (yearlyDepreciation * 0);
            bookValueYear1 = machineCost - (yearlyDepreciation * 1);
            bookValueYear2 = machineCost - (yearlyDepreciation * 2);
            bookValueYear3 = machineCost - (yearlyDepreciation * 3);
            bookValueYear4 = machineCost - (yearlyDepreciation * 4);
            bookValueYear5 = machineCost - (yearlyDepreciation * 5);
            bookValueYear6 = machineCost - (yearlyDepreciation * 6);
            bookValueYear7 = machineCost - (yearlyDepreciation * 7);
            bookValueYear8 = machineCost - (yearlyDepreciation * 8);
            bookValueYear9 = machineCost - (yearlyDepreciation * 9);
            bookValueYear10 = machineCost - (yearlyDepreciation * 10);
    
            strBookValueYear0 = $"{bookValueYear0:F}";
            strBookValueYear1 = $"{bookValueYear1:F}";
            strBookValueYear2 = $"{bookValueYear2:F}";
            strBookValueYear3 = $"{bookValueYear3:F}";
            strBookValueYear4 = $"{bookValueYear4:F}";
            strBookValueYear5 = $"{bookValueYear5:F}";
            strBookValueYear6 = $"{bookValueYear6:F}";
            strBookValueYear7 = $"{bookValueYear7:F}";
            strBookValueYear8 = $"{bookValueYear8:F}";
            strBookValueYear9 = $"{bookValueYear9:F}";
            strBookValueYear10 = $"{bookValueYear10:F}";
    
            strAccumulatedDepreciation1 = $"{yearlyDepreciation * 1:F}";
            strAccumulatedDepreciation2 = $"{yearlyDepreciation * 2:F}";
            strAccumulatedDepreciation3 = $"{yearlyDepreciation * 3:F}";
            strAccumulatedDepreciation4 = $"{yearlyDepreciation * 4:F}";
            strAccumulatedDepreciation5 = $"{yearlyDepreciation * 5:F}";
            strAccumulatedDepreciation6 = $"{yearlyDepreciation * 6:F}";
            strAccumulatedDepreciation7 = $"{yearlyDepreciation * 7:F}";
            strAccumulatedDepreciation8 = $"{yearlyDepreciation * 8:F}";
            strAccumulatedDepreciation9 = $"{yearlyDepreciation * 9:F}";
            strAccumulatedDepreciation10 = $"{yearlyDepreciation * 10:F}";
    
            double depreciatiableAmount = machineCost - salvageValue;
            //depreciationRate = 100 / estimatedLife;
            yearlyDepreciation = depreciatiableAmount / estimatedLife;
    
            strDepreciableAmount = $"{(depreciatiableAmount):n}";
            strDepreciationRate = $"{(depreciationRate):n}";
            strYearlyDepreciation = $"{yearlyDepreciation:f}";
    
            WriteLine("====================================");
            WriteLine("Depreciation - Straight-Line Method");
            WriteLine("------------------------------------");
            WriteLine("Machine Cost:        {0}", machineCost);
    
            WriteLine("Salvage Value:       {0}", salvageValue);
            WriteLine("Estimate Life:       {0} Years", estimatedLife);
            WriteLine("Depreciation Rate:   {0}%", depreciationRate);
            WriteLine("------------------------------------");
            WriteLine("Depreciable Amount:  {0}", depreciatiableAmount);
            WriteLine("Yearly Depreciation: {0}", yearlyDepreciation);
            WriteLine("====================================");
        }
    }
    
    <div class="common-font">
        <h1 class="fw-bold text-center">Machine Depreciation Evaluation</h1>
        
        <h2 class="fw-bold text-center">Straight-Line Method</h2>
        
        <hr />
        
        <form name="PayrollEvaluation" method="post">
            <table align="center" style="width: 325px" class="table">
                <tr>
                    <td style="width: 150px" class="fw-bold">Machine Cost:</td>
                    <td><input type="text" style="" id="txtMachineCost"
                           name="txtMachineCost" value="@machineCost" class="form-control ta-right" /></td>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td class="fw-bold">Salvage Value:</td>
                    <td><input type="text" id="txtSalvageValue"
                           name="txtSalvageValue" value="@salvageValue" class="form-control ta-right" /></td>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td class="fw-bold">Estimated Life:</td>
                    <td><input type="text" id="txtEstimatedLife"
                           name="txtEstimatedLife" value="@estimatedLife" class="form-control ta-right" /></td>
                    <td>years</td>
                </tr>
            </table>
                
            <hr />
                
            <table style="width: 300px" align="center">
                <tr>
                    <td style="width: 50px">&nbsp;</td>
                    <td><input type="submit" value="Calculate Depreciation" name="btnCalculate" style="width: 200px" /></td>
                </tr>
            </table>
        </form>
    
        <hr />
    
        <table style="width: 325px" align="center" class="table">
            <tr>
                <td class="fw-bold">Machine Cost:</td>
                <td>@machineCost</td>
            </tr>
            <tr>
                <td class="fw-bold">Salvage Value:</td>
                <td>@salvageValue</td>
            </tr>
            <tr>
                <td class="fw-bold">Estimate Life:</td>
                <td>@estimatedLife Years</td>
            </tr>
            <tr>
                <td class="fw-bold">Depreciation Rate:</td>
                <td>@strDepreciationRate %</td>
            </tr>
            <tr>
                <td class="fw-bold">Depreciable Amount:</td>
                <td>@strDepreciableAmount</td>
            </tr>
            <tr>
                <td class="fw-bold">Yearly Depreciation:</td>
                <td>@strYearlyDepreciation /month</td>
            </tr>
        </table>
    
        <hr />
        
        <table style="width: 625px" align="center" border="3">
            <tr style="border-bottom: 1px solid black">
                <td class="fw-bold">Year</td>
                <td class="ta-center fw-bold">Yearly Depreciation</td>
                <td class="fw-bold">Book Value</td>
                <td class="fw-bold">Accumulated Depreciation</td>
            </tr>
            <tr style="border-bottom: 1px solid black">
                <td class="ta-center">@year</td>
                <td></td>
                <td>@strBookValueYear0</td>
                <td></td>
            </tr>
    @if (bookValueYear1 is >= 0)
    {
            <tr style="border-bottom: 1px solid black">
                <td class="ta-center">@(year + 1)</td>
                <td class="ta-center">@strYearlyDepreciation</td>
                <td>@strBookValueYear1</td>
                <td class="ta-center">@strAccumulatedDepreciation1</td>
            </tr>
    }
    @if (bookValueYear2 is >= 0)
    {
            <tr style="border-bottom: 1px solid black">
                <td class="ta-center">@(year + 2)</td>
                <td class="ta-center">@strYearlyDepreciation</td>
                <td>@strBookValueYear2</td>
                <td class="ta-center">@strAccumulatedDepreciation2</td>
            </tr>
    }
    @if (bookValueYear3 is >= 0)
    {
            <tr style="border-bottom: 1px solid black">
                <td class="ta-center">@(year + 3)</td>
                <td class="ta-center">@strYearlyDepreciation</td>
                <td>@strBookValueYear3</td>
                <td class="ta-center">@strAccumulatedDepreciation3</td>
            </tr>
    }
    @if (bookValueYear4 is >= 0)
    {
            <tr style="border-bottom: 1px solid black">
                <td class="ta-center">@(year + 4)</td>
                <td class="ta-center">@strYearlyDepreciation</td>
                <td>@strBookValueYear4</td>
                <td class="ta-center">@strAccumulatedDepreciation4</td>
            </tr>
    }
    @if (bookValueYear5 is >= 0)
    {
            <tr style="border-bottom: 1px solid black">
                <td class="ta-center">@(year + 5)</td>
                <td class="ta-center">@strYearlyDepreciation</td>
                <td>@strBookValueYear5</td>
                <td class="ta-center">@strAccumulatedDepreciation5</td>
            </tr>
    }
    @if (bookValueYear6 is >= 0)
    {
            <tr style="border-bottom: 1px solid black">
                <td class="ta-center">@(year + 6)</td>
                <td class="ta-center">@strYearlyDepreciation</td>
                <td>@strBookValueYear6</td>
                <td class="ta-center">@strAccumulatedDepreciation6</td>
            </tr>
    }
    @if (bookValueYear7 is >= 0)
    {
            <tr style="border-bottom: 1px solid black">
                <td class="ta-center">@(year + 7)</td>
                <td class="ta-center">@strYearlyDepreciation</td>
                <td>@strBookValueYear7</td>
                <td class="ta-center">@strAccumulatedDepreciation7</td>
            </tr>
    }
    @if (bookValueYear8 is >= 0)
    {
            <tr style="border-bottom: 1px solid black">
                <td class="ta-center">@(year + 8)</td>
                <td class="ta-center">@strYearlyDepreciation</td>
                <td>@strBookValueYear8</td>
                <td class="ta-center">@strAccumulatedDepreciation8</td>
            </tr>
    }
    @if (bookValueYear9 is >= 0)
    {
            <tr style="border-bottom: 1px solid black">
                <td class="ta-center">@(year + 9)</td>
                <td class="ta-center">@strYearlyDepreciation</td>
                <td>@strBookValueYear9</td>
                <td class="ta-center">@strAccumulatedDepreciation9</td>
            </tr>
    }
    @if (bookValueYear10 is >= 0)
    {
                <tr style="border-bottom: 1px solid black">
                    <td class="ta-center">@(year + 10)</td>
                <td class="ta-center">@strYearlyDepreciation</td>
                <td>@strBookValueYear10</td>
                <td class="ta-center">@strAccumulatedDepreciation10</td>
            </tr>
    }
        </table>
    </div>
  2. To execute, on the main menu, click Debug -> Start Without Debugging
  3. Change the value in the Machine Cost text box to 8568.95
  4. Change the value in the Salvage Value text box to 550 and press Enter
  5. Change the value in the Estimated Life text box to 5 and click the button

    Conditional Statements

  6. Return to your programming environment

Previous Copyright © 2001-2023, FunctionX Friday 17 December 2021 Next