jmal salih

jmal salih

  • NA
  • 8
  • 7.2k

for loop

May 14 2014 4:14 AM
this code work only on number from 1 to 10 repeated 3 times for example
with other numbers do nothing here is my code:
private void button1_Click(object sender, EventArgs e)
{

if (textBox1.Text==""||textBox1.Text=="")
{
MessageBox.Show("enter the numbers");
}
else
{
string file = @"c:\\test.txt";

try
{
// Check if file already exists. If yes, delete it.
if (File.Exists(file))
{
File.Delete(file);
}
int x = Int32.Parse(textBox1.Text);
int y = Int32.Parse(textBox2.Text);
int count = Int32.Parse(textBox3.Text);
System.IO.StreamWriter sw = new System.IO.StreamWriter(file);
for (int i = x; i <= count; i++)

for (int j = x; j <= y; j++)
{

sw.WriteLine(i);

}
sw.Close();
}
catch (Exception Ex)
{
MessageBox.Show(Ex.ToString());
}
}

Answers (1)