所以我一直试图弄清楚它是如何工作的,但我的书并不能很好地解释它.
有人可以解释一下为什么结果是45?它不应该是55吗?
这是我的代码,结果如下图所示
public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { int loopStart; int loopEnd; int answer = 0; loopStart = int.Parse(textBox1.Text); loopEnd = int.Parse(textBox2.Text); //The code will keep running as long as End is bigger than start for (int i = loopStart; i < loopEnd; i++) { answer = answer + i; } MessageBox.Show(answer.ToString()); } }