加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

vb.net – Do..While …循环

发布时间:2020-12-17 00:18:02 所属栏目:大数据 来源:网络整理
导读:我的学习书对下面的代码做了如下陈述: **“计算机评估Do …循环语句中的循环条件,以确定是否应该处理循环指令.在这种情况下,inputales String.Empty条件将输入销售变量的最大容量与String.Empty值.如您所知,String.Empty值表示零长度或空的字符串,如果input
我的学习书对下面的代码做了如下陈述:

**“计算机评估Do …循环语句中的循环条件,以确定是否应该处理循环指令.在这种情况下,inputales<> String.Empty条件将输入销售变量的最大容量与String.Empty值.如您所知,String.Empty值表示零长度或空的字符串,如果inputsales变量为空,则循环条件计算为True,计算机处理循环指令.*如果另一方面inputales变量不为空,循环条件的计算结果为false,计算机跳过循环指令.

根据代码,我认为它是相反的:…虽然inputales值不为空,但它应该计算为true并处理循环,如果它是空的,它应该计算为false并跳过循环?请看下面.非常感谢你的帮助!

Option Explicit On
Option Strict On

Imports System.Globalization


Public Class SalesForm

    Private Sub exitButton_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles exitButton.Click
        Me.Close()
    End Sub

    Private Sub calcButton_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles calcButton.Click
        Const prompt As String = "Enter a sales amount. Click cancel to end."
        Const title As String = "Sales Entry"
        Dim inputsales As String
        Dim sales As Decimal
        Dim salesCounter As Integer
        Dim salesaccumulator As Decimal
        Dim salesAverage As Decimal
        Dim isconverted As Boolean

        inputsales = InputBox(prompt,title,"0")

        **Do While inputsales <> String.Empty
            isconverted = Decimal.TryParse(inputsales,NumberStyles.Currency,NumberFormatInfo.CurrentInfo,sales)

            If isconverted = True Then
                salesCounter = salesCounter + 1
                salesaccumulator = salesaccumulator + sales
            Else
                MessageBox.Show("Please re-entere the sales amount.","sales Express",MessageBoxButtons.OK,MessageBoxIcon.Information)
            End If
            inputsales = InputBox(prompt,"0")
        Loop**

        If salesCounter > 0 Then
            salesAverage = salesaccumulator / Convert.ToDecimal(salesCounter)
            averageLabel.Text = salesAverage.ToString("C2")
            Label2.Text = salesCounter.ToString
        Else
            averageLabel.Text = "0"
        End If
    End Sub
End Class
你是绝对正确的,这本书是错的(希望,作者只是偶然地颠倒了真/假;否则,我会得到另一本书).我的建议更正(添加一些):

As you know,the String.Empty value represents a zero length,or empty,string. If the inputsales variable is not empty,the loop condition evaluates to True,and the computer processes the loop instructions (and then jumps back to the top of the loop and reevaluates the condition). If,on the other hand,the inputsales variable is empty,the loop condition evaluates to False,and the computer skips over the loop instructions (and continues with the first statement after the loop).

正如@xanatos所说:恭喜你在别人的文字中抓住你的第一个错误.所以问题就是1,我会说这对你的编程生涯很??有希望.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读