For 循环步骤 -1 [英] For Loop Step -1

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

问题描述

我想知道为什么这个循环在 VB.NET 中没有显示任何内容.

I want to know why this loop doesn't show anything in VB.NET.

我认为这段代码会造成无限循环.但它没有显示任何东西.

I think this code will create an infinite loop. But it doesn't show anything.

Dim i as Integer
For i = 1 to 3 Step - 1
    MessageBox.Show(i)
Next

该循环与此代码(在 java/c# 中)不同吗?

Is that loop different with this code (in java/c#) ?

for(int i = 1;i <= 3;i--)
{
  // print i
}

推荐答案

http://msdn.microsoft.com/en-us/library/5z06z1kb.aspx对于负步长,循环仅在 counter >= end 时执行.因此,在 i = 1 的情况下,它小于结束值,因此循环根本不执行.

http://msdn.microsoft.com/en-us/library/5z06z1kb.aspx With a negative step size the loop only executes if counter >= end. So in this case with i = 1, that is less than the ending value so the loop doesn't execute at all.

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

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