“做同时” "环路"和“While” " WEND"循环。有什么不同? [英] "Do While" "Loop" and "While" "Wend" Loop. What's the difference?

查看:194
本文介绍了“做同时” "环路"和“While” " WEND"循环。有什么不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在stackoverflow中读取一些答案我看到一个 wend 循环。我习惯了 do while loop ,所以我想知道这两个循环之间有什么区别。

Reading some answers in stackoverflow I saw a while wend loop. I'm used to the do while loop, so I was wondering what would be the difference between this two loops.

我做了一些测试(下面的代码),两者似乎都给了我相同的结果。

I did some testing (code below) and both seem to give me the same results.

Sub test_loop_1()
Dim i As Integer
i = 1
Do While i < 10
    Cells(i, 1) = i
    i = i + 1
Loop

End Sub

Sub test_loop_2()
Dim i As Integer
i = 1
While i < 10
    Cells(i, 1) = i
    i = i + 1
Wend

End Sub


推荐答案

@vsoraas突出显示了关键的区别,我将展开。虽然/ Wend是从Basic和Do / Loop的宿醉应该是您首选的语法,因为:

@vsoraas has highlighted the key difference and I'll expand on that. While/Wend is a hangover from Basic and Do/Loop should be your preferred syntax because:


  1. 它支持检查条件< b> before enter the loop
    Do While ... Loop
    (零个或多个循环执行)

  2. 它支持检查条件之后进入循环
    Do ...循环while
    (一个或多个循环执行)

  3. 它不支持特定条件
    Do ...(一些逻辑)(Exit Do)... Loop
    (一个或多个循环执行,潜在无限)

  1. It supports checking the condition before entering the loop Do While ... Loop (zero or more loop executions)
  2. It supports checking the condition after entering the loop Do ... Loop While (one or more loop executions)
  3. It supports no specific condition Do ...(some logic) (Exit Do) ... Loop (one or more loop executions, potentially infinite)

这篇关于“做同时” &QUOT;环路&QUOT;和“While” &QUOT; WEND&QUOT;循环。有什么不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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