为什么我在右括号中的第一组数字卡在 21 上?
Why is my first set of numbers on the closed parenthesis stuck on 21?
我希望输出的第一组数字为 0-20,第二组数字为 0-100,但不是 0、1、2、3、4、5,而是 0、5、10基本上跳过每 5 个。这是我的代码和输出的屏幕截图。
代码:
输出:
你有几个选择...
选项 1:
For a As Integer = 0 To 20
Dim b As Integer = a * 5
Console.WriteLine("index number:({0}) = {1}", a, b)
Next
选项 2:
Dim b As Integer = 0
For a As Integer = 0 To 20
Console.WriteLine("index number:({0}) = {1}", a, b)
b = b + 5
Next
选项 3:
Dim a As Integer = 0
Dim b As Integer = 0
While a <= 20
Console.WriteLine("index number:({0}) = {1}", a, b)
a = a + 1
b = b + 5
End While
在 C# 中,您可以这样做:
for(int a=0,b=0; a<=20; a++,b+=5) {
Console.WriteLine("index number:({0}) = {1}", a, b);
}
我希望输出的第一组数字为 0-20,第二组数字为 0-100,但不是 0、1、2、3、4、5,而是 0、5、10基本上跳过每 5 个。这是我的代码和输出的屏幕截图。
代码:
输出:
你有几个选择...
选项 1:
For a As Integer = 0 To 20
Dim b As Integer = a * 5
Console.WriteLine("index number:({0}) = {1}", a, b)
Next
选项 2:
Dim b As Integer = 0
For a As Integer = 0 To 20
Console.WriteLine("index number:({0}) = {1}", a, b)
b = b + 5
Next
选项 3:
Dim a As Integer = 0
Dim b As Integer = 0
While a <= 20
Console.WriteLine("index number:({0}) = {1}", a, b)
a = a + 1
b = b + 5
End While
在 C# 中,您可以这样做:
for(int a=0,b=0; a<=20; a++,b+=5) {
Console.WriteLine("index number:({0}) = {1}", a, b);
}