このチュートリアルを進めている間、自分の間違いがわかりません。
次の出力:
Warning 1 Possible mistaken empty statement (Line 32)
Error 2 The name 'i' does not exist in the current context (Line 35)
Error 3 The name 'i' does not exist in the current context (Line 36)
次のコードで取得されます。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Loops
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void btnForLoops_Click(object sender, EventArgs e)
{
int loopStart;
int loopEnd;
int answer;
//store the numbers from the text boxes into the two new variables:
loopStart = int.Parse(tbLoopStart.Text);
loopEnd = int.Parse(tbLoopEnd.Text);
for (int i = loopStart; i <= loopEnd; i++) ;
{
answer = answer + i;
listBox1.Items.Add("i = " + i + "answer = " + answer.ToString()); //the display shows as i=1 answer = 1, i=2 answer = 3, etc...
}
}
}
}