继续For循环 [英] Continue For loop

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

问题描述

我有以下的代码:

pre $ $ b sname = arr(x)
如果instr(sname,配置项)然后
'**(这里我想去循环中的下一个x而不是完成下面的代码)**

'//其他代码复制过去并做各种各样的东西

下一个x

所以我认为我可以简单地使用 Then Next x 语句,但是这会给出一个no for statement declared错误。 >

那么我可以在之后加入如果instr(sname,Configuration item)然后来继续下一步x的价值?

解决方案

您不能使用下一步 。您可以使用 GoTo 语句来实现您想要做的事情,但实际上, GoTo 应该是保留用于替代方案的设计和不切实际的情况。

在您的情况中,有一个非常简单,干净且可读的替代方案:

 如果不是InStr(sname,配置项)然后
'//其他代码复制过去做各种各样的东西
结束如果


I have the following code

For x = LBound(arr) To UBound(arr)

    sname = arr(x)  
    If instr(sname, "Configuration item") Then  
        '**(here i want to go to next x in loop and not complete the code below)**  

    '// other code to copy past and do various stuff

Next x  

So I thought I could simply have the statement Then Next x, but this gives a "no for statement declared" error.

So what can I put after the If instr(sname, "Configuration item") Then to make it proceed to the next value for x?

解决方案

You can't use Next like that. You could achieve something like what you're trying to do using a GoTo statement instead, but really, GoTo should be reserved for cases where the alternatives are contrived and impractical.

In your case, there's a really simple, clean, and readable alternative:

    If Not InStr(sname, "Configuration item") Then
        '// other code to copy past and do various stuff
    End If

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

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