C#循环,急!
有个C#程序,请问其中的几个循环condition1~condition14,是上一个循环先运行完了之后将所有数据传输给下一个循环。还是上一个循环先运行一遍将数据传输给下一个,然后 i++,再从新开始循环?如果是前者,我想要达到后一种目的,该怎么办?
//程序运行过程
private void button3_Click(object sender, System.EventArgs e)
{
this.textBox84.Text = "";
this.textBox85.Text = "";
int i, i1, i2, i3, i4, i5, j, k = 0;
int numofresult = 0;
string s;
string result = "输出结果为:" + "\r\n";
DialogResult dr;
for (j = 0; j < 50; j++)
{
if (ifwanttocheck[j])
k++;
}
if (k == 0)
{
MessageBox.Show("没有确定任何约束条件!", "警告", MessageBoxButtons.OKCancel);
return;
}
if (k < 8)
{
dr = MessageBox.Show("约束条件太少,这将需要花费长时间等待输出结果!", "提示", MessageBoxButtons.OKCancel);
if (dr == DialogResult.Cancel)
return;
}
for (i = 1; i <= 100; i++)
{
for (i1 = i + 1; i1 <= 100; i1++)
{
for (i2 = i1 + 1; i2 <= 100; i2++)
{
for (i3 = i2 + 1; i3 <= 100; i3++)
{
for (i4 = i3 + 1; i4 <= 100; i4++)
{
for (i5 = i4 + 1; i5 <= 100; i5++)
{
data[0] = i;
data[1] = i1;
data[2] = i2;
data[3] = i3;
data[4] = i4;
data[5] = i5;
//data[0]=2;
//data[1]=4;
//data[2]=6;
//data[3]=8;
//data[4]=10;
//data[5]=12;
if (ifwanttocheck[0])
{
condition1 mycondition1 = new condition1(data, dataofsplitting1, parameter1);
if (!mycondition1.checkcondition1()) continue;
}
if (ifwanttocheck[1])
{
condition2 mycondition2 = new condition2(data, parameter2);
if (!mycondition2.checkcondition2()) continue;
//~略
if (ifwanttocheck[16])
{
condition16 mycondition17 = new condition16(data, dataofsplitting17, parameter17);
if (!mycondition17.checkcondition16()) continue;
}
s = i.ToString() + "-" + i1.ToString() + "-" + i2.ToString() + "-" + i3.ToString() + "-" + i4.ToString() + "-" + i5.ToString();
numofresult++;
result += s + "\r\n";
s = "";
}
}
}
}
}
}
this.textBox84.Text = result;
this.textBox85.Text = numofresult.ToString();
}
忘了加condition1了,其他的condition几乎一样。
namespace @@
{
/// <summary>
/// condition1 的摘要说明。
/// </summary>
public class condition1
{
int[]data=new int[6];
int[][] dataofsplitting=new int[8][];
int[] parameter=new int[4];
ArrayList myarraylist=new ArrayList();
ArrayList temp=new ArrayList();
public condition1(int[]data,int[][]dataofsplitting,int[]parameter)
{
this.data=data;
for(int i=0;i<8;i++)
this.dataofsplitting[i]=new int[15];
this.dataofsplitting=dataofsplitting;
this.parameter=parameter;
}
public bool checkcondition1()
{
baseofcondition();
if(!checkcondition11())
return false;
else if(!checkcondition12())
return false;
else if(!checkcondition13())
return false;
else
return true;
}
private void baseofcondition()
{
int i,j,k;
for(k=0;k<data.Length;k++)
{
for(i=0;i<8;i++)
{
for(j=0;j<dataofsplitting[i].Length;j++)
{
if(dataofsplitting[i][j]==data[k])
{
myarraylist.Add(i);
goto next;
}
}
}
next:;
}
}
private bool checkcondition11()
{
int i,j;
bool flag;
int numofsplitting=1;
for(i=0;i<myarraylist.Count-1;i++)
{
flag=false;
for(j=i+1;j<myarraylist.Count;j++)
{
if((int)myarraylist[j]==(int)myarraylist[i])
{
flag=true;
break;
}
}
if(!flag)
{
numofsplitting++;
temp.Add(myarraylist[i]);
}
}
temp.Add(myarraylist[myarraylist.Count-1]);
if(parameter[0]<=numofsplitting&&numofsplitting<=parameter[1])
return true;
else
return false;
}
private bool checkcondition12()
{
int i,j;
int num;
for(i=0;i<myarraylist.Count-2;i++)
{
num=1;
for(j=i+1;j<myarraylist.Count;j++)
{
if((int)myarraylist[j]==(int)myarraylist[i])
num++;
}
if(num>3)
return false;
}
return true;
}
private bool checkcondition13()
{
int i,j;
int sumelement=0;
for(i=0;i<temp.Count;i++)
{
for(j=0;j<dataofsplitting[(int)temp[i]].Length;j++)
{
if(dataofsplitting[(int)temp[i]][j]!=0)
sumelement++;
}
}
if(parameter[2]<=sumelement&&sumelement<=parameter[3])
return true;
else
return false;
}
}
}
[ 本帖最后由 伤痕累累 于 2010-11-10 14:33 编辑 ]