对于下一个循环 - 手动可能是错误的 [英] For Next Loop - Manual Might Be Wrong

查看:64
本文介绍了对于下一个循环 - 手动可能是错误的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用VB2003,我刚刚从书中提到了一个例子:


"注意:你也可以使用以下方法对For循环中的索引变量进行十分转换

可选AS数据类型子句,只要索引变量不是已经声明了eslewhere的
。 (这是Visual Basic.net 2003的新功能)


然后它给出了一个例子:

for intLoopIndex As Integer = 0 To 1

''下一行我有假',因为他们用它来打印一个数组

元素所以像Foo(intLoopIndex)

Console.WriteLine(" Hello")

Next intLoopIndex


它没有提到选项strict on和option explicit on。我已经打开了他们的b $ b。

我的简单解决方案就是先调暗它,因为它抱怨

intLoopIndex未被声明。


我假设它是由于Option Strict和Option Explicit

而不是书中的错误(某种方式)。


Miro

Im using VB2003 and i just pulled an example out of the book that says this:

"Note: also that you can decalre the index variable in a For Loop using the
optional AS datatype clause, as long as the index variable isnt already
declared eslewhere. ( This is new to Visual Basic.net 2003 )

It then gives the example :

For intLoopIndex As Integer = 0 To 1
''This next line i have dummy''d down cause they use it to print an array
element so like Foo( intLoopIndex )
Console.WriteLine("Hello")
Next intLoopIndex

It does not mention having option strict on and option explicit on. I have
them both on.
My simple solution is to just dim it before, cause it complaines that
intLoopIndex is not declared.

Im assuming its either because of the Option Strict and Option Explicit
and not a typo ( somehow ) in the book.

Miro

推荐答案

这对我来说很好用... Optin Strict开启和关闭以及选项明确

和关闭


对于x为整数= 0到5


''''做的东西


下一页


-

-iwdu15
this works fine for me...with Optin Strict on and off and Option Explicit on
and off

For x As Integer = 0 To 5

''''Do Stuff

Next

--
-iwdu15


Hello Miro,

我只在VB6和VB.Net上对2.0框架进行了测试..在你的Next语句中包含

索引器会大大降低长期运行中的性能

循环。你当然不会注意到低到中等程度的降级

(比如说,小于250,000)。


-Boo
Hello Miro,

I''ve only tested this on VB6 and VB.Net on 2.0 framework.. Including the
indexer in your Next statement drasticly decreases performance in long-running
loops. You certainly wont notice a degredation on low to moderate interations
(say, less than 250,000).

-Boo

我正在使用VB2003,我刚刚从书中拿出了一个例子,说明了

这个:


"注意:还有你可以使用可选的AS数据类型子句对For循环

中的索引变量进行十分转换,只要索引变量

不是已经声明为eslewhere。 (这是Visual Basic.net的新内容

2003)


然后给出了一个例子:


For intLoopIndex As Integer = 0到1

''下一行我有假',因为他们用它来打印一个

数组

元素就像Foo(intLoopIndex)

Console.WriteLine(" Hello")

下一个intLoopIndex

它没有提到选项严格on和明确的选项。

我已经

他们两个都开。

我的简单解决方案是在之前调暗它,因为它抱怨

intLoopIndex未声明。

我假设它是因为Option Strict和Option

明确而不是错字(不知何故)预订。


Miro
Im using VB2003 and i just pulled an example out of the book that says
this:

"Note: also that you can decalre the index variable in a For Loop
using the optional AS datatype clause, as long as the index variable
isnt already declared eslewhere. ( This is new to Visual Basic.net
2003 )

It then gives the example :

For intLoopIndex As Integer = 0 To 1
''This next line i have dummy''d down cause they use it to print an
array
element so like Foo( intLoopIndex )
Console.WriteLine("Hello")
Next intLoopIndex
It does not mention having option strict on and option explicit on.
I have
them both on.
My simple solution is to just dim it before, cause it complaines that
intLoopIndex is not declared.
Im assuming its either because of the Option Strict and Option
Explicit and not a typo ( somehow ) in the book.

Miro





" Miro" < mi ****** @gold.netwrote in message

news:Om ************** @ TK2MSFTNGP04.phx.gbl ...



:我正在使用VB2003,我刚刚从书中拿出一个例子说明了

:这个:



:"注意:你也可以使用

对For循环中的索引变量进行十进制:

:可选的AS数据类型子句,只要索引变量不是已经

:声明为eslewhere。 (这是Visual Basic.net 2003的新功能)



:然后给出了一个例子:



:对于intLoopIndex As Integer = 0到1

:''下一行我有假',因为他们用它来打印数组

:element所以像Foo(intLoopIndex)

:Console.WriteLine(" Hello")

:Next intLoopIndex



:它没有提到选项严格和选项显式。我



:他们两个都开。

:我的简单解决方案就是之前调暗它,因为它抱怨

:未声明intLoopIndex。



:我假设它是因为Option Strict和Option Explicit

:而不是书中的错字(不知何故)。



:Miro

给出的例子是正确的。以下编译在VB.net中很好

2.0:


''----------------- -----------------------

Option Strict


进口系统

公共模块[模块]

Public Sub Main()


Dim Arr(1)As String

Arr(0)=" Hello"

Arr(1)=" World"


for intLoopIndex As Integer = 0 To 1

Console.WriteLine(Arr(intLoopIndex))

下一个intLoopIndex


结束子

结束模块

''--------------------------------------- -

Ralf

-

-

------------ ----------------------------------------------

* ^〜^ ^〜^ *

* _ {~~} {~~} _ *

* / _``> *< > *<'''_ _ \\ * *

*(\ --_)++)(++(_ - /)*

-------------------------------------------------- --------

合气道没有高级学生 - 只有

有能力的初学者。没有先进的技术 -

只有正确应用基本原则。

"Miro" <mi******@golden.netwrote in message
news:Om**************@TK2MSFTNGP04.phx.gbl...
:
: Im using VB2003 and i just pulled an example out of the book that says
: this:
:
: "Note: also that you can decalre the index variable in a For Loop using
: the
: optional AS datatype clause, as long as the index variable isnt already
: declared eslewhere. ( This is new to Visual Basic.net 2003 )
:
: It then gives the example :
:
: For intLoopIndex As Integer = 0 To 1
: ''This next line i have dummy''d down cause they use it to print an array
: element so like Foo( intLoopIndex )
: Console.WriteLine("Hello")
: Next intLoopIndex
:
: It does not mention having option strict on and option explicit on. I
: have
: them both on.
: My simple solution is to just dim it before, cause it complaines that
: intLoopIndex is not declared.
:
: Im assuming its either because of the Option Strict and Option Explicit
: and not a typo ( somehow ) in the book.
:
: Miro
The example given is correct. The following compiles just fine in VB.net
2.0:

''----------------------------------------
Option Strict

Imports System

Public Module [module]
Public Sub Main()

Dim Arr(1) As String
Arr(0) = "Hello"
Arr(1) = "World"

For intLoopIndex As Integer = 0 To 1
Console.WriteLine(Arr(intLoopIndex))
Next intLoopIndex

End Sub
End Module
''----------------------------------------
Ralf
--
--
----------------------------------------------------------
* ^~^ ^~^ *
* _ {~ ~} {~ ~} _ *
* /_``>*< >*<''''_\ *
* (\--_)++) (++(_--/) *
----------------------------------------------------------
There are no advanced students in Aikido - there are only
competent beginners. There are no advanced techniques -
only the correct application of basic principles.


这篇关于对于下一个循环 - 手动可能是错误的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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