Do Loop语句不循环 [英] Do Loop statement not looping

查看:58
本文介绍了Do Loop语句不循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行执行乘法的Do While循环语句.假设将我从数字1到9输入的数字乘以整数.我有很好的乘法运算,并且运算没有错误,但是不会求下一个值. 我怀疑这是因为我没有AddItem语句,但是它给了我错误,就像我疯了一样.我想念什么?

I'm trying to perform a Do While Loop statement that performs multiplication. It's suppose to multiple the number I input from numbers 1 to 9. I have the multiplication good to go and it's performing with no errors but it is not going to the next value. I suspect it is because I don't have an AddItem statement but it gives me errors, like I'm the crazy one. What am I missing?

       Dim intNumber As Integer = 1
        Dim intNumber As Integer = 1

推荐答案

您缺少的内容可能足以对所使用的材料进行研究,练习和学习,以便了解如何执行它所提供的.另外,所使用的方法似乎并不是最新的.

What you are missing is probably enough studying, practice and learning of the material you are working with in order to understand how to perform what it provides. Plus the methods used don't seem up to date really.

如果intNumber从1开始,则为< 10,因此循环将不会运行,因为直到intNumber< 10英寸表示执行循环,直到intNumber小于10并且小于10,这样循环才能执行任何操作.

Well if intNumber starts out at 1 then it is < 10 so the loop will not run since "Do Until intNumber < 10" means do the loop until intNumber is less than 10 and it is less than 10 so the loop can't Do anything.

也许下面是您想要的.但是即使如此,所有将会发生的事情是intNumber将达到10,并且循环将停止.循环内没有其他代码,因此intNumber的值增加除了增加inNumber的值直到达到该值之前,实际上并没有执行任何操作 10.

Maybe below is what you want. But even then all that will happen is intNumber will reach 10 and the loop will stop. No other code is inside the loop so intNumber increasing in value does nothing really except increase intNumbers value until it reaches 10.

Do While intNumber < 10
     intNumber += 1
Loop

其余的代码似乎也很奇怪.也许是这样.但是,假设TextBox中的字符串可以转换为数字,因为可以在TextBox中键入任何内容,所以这是一个坏主意.所以你真的应该使用 TryParse 方法用于验证在麻烦运行循环代码之前,是否可以将TextBox的字符串解析为整数类型,如果不能再显示MessageBox,则警告TextBox中的文本无效.

The rest of your code seems odd also. Maybe this. However it is a bad idea to assume that a string in a TextBox can be converted to a number as anything can be typed into a TextBox. So you should really use a TryParse method to validate if the TextBox's string can be parsed to an integer type prior to bothering running the loop code and if it can not then display a MessageBox warning the text in the TextBox is invalid.

 lblTable.Text = "" ' Clear labels text
 Dim intNumber As Integer = 1
 Do While intNumber < 10
         intNumber += 1
         lblTable.Text &= txtNumber.Text & " * " & intNumber.ToString & " = " & (intNumber * Val(txtNumber.Text)).ToString & vbCrLf
 Loop


这篇关于Do Loop语句不循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆