首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Continue For循环

Continue For循环
EN

Stack Overflow用户
提问于 2011-05-05 18:05:50
回答 10查看 222.3K关注 0票数 65

我有以下代码

代码语言:javascript
复制
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  

所以我想我可以简单地使用Then Next x语句,但这会给出一个"no for statement could“错误。

那么,我可以在If instr(sname, "Configuration item") Then后面放什么,以使其继续到x的下一个值?

EN

回答 10

Stack Overflow用户

回答已采纳

发布于 2011-05-05 18:25:03

您正在考虑像Java'sPython's这样的continue语句,但是VBA没有这样的本机语句,并且您不能像那样使用VBA的Next

您可以使用GoTo语句来实现您想要实现的功能,但实际上,GoTo应该保留给那些人为设计的、不切实际的替代方案。

在只有一个"continue“条件的情况下,有一个非常简单、干净和可读的替代条件:

代码语言:javascript
复制
    If Not InStr(sname, "Configuration item") Then
        '// other code to copy paste and do various stuff
    End If
票数 53
EN

Stack Overflow用户

发布于 2012-10-19 02:08:43

您可以使用GoTo

代码语言:javascript
复制
Do

    '... do stuff your loop will be doing

    ' skip to the end of the loop if necessary:
    If <condition-to-go-to-next-iteration> Then GoTo ContinueLoop 

    '... do other stuff if the condition is not met

ContinueLoop:
Loop
票数 98
EN

Stack Overflow用户

发布于 2015-01-20 04:39:24

代码语言:javascript
复制
For i=1 To 10
    Do 
        'Do everything in here and

        If I_Dont_Want_Finish_This_Loop Then
            Exit Do
        End If 

        'Of course, if I do want to finish it,
        'I put more stuff here, and then...

    Loop While False 'quit after one loop
Next i
票数 25
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5895908

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档