没分了
 StringBuilder shopText = new StringBuilder();
            List<Let.Model.ModelAllList> modelList = new Let.BLL.photoList().ExecuteReader(CommandType.StoredProcedure, "P_ShopList",
                   new SqlParameter("@startIndex", AspNetPager1.StartRecordIndex),
                   new SqlParameter("@endIndex", AspNetPager1.EndRecordIndex));            if (modelList.Count > 0)
            {
                int count = 0;
                for (int n = 0; n < 4; n++)
                {
                    shopText.Append("<div class='divlist'>");                    for (int i = 0; i < modelList.Count; i++)
                    {
                        if (i.Equals(30))
                        {
                            count = i;
                            break;
                        }                        if (i.Equals(60))
                        {
                            count = i;
                            break;
                        }                        if (i.Equals(90))
                        {
                            count = i;
                            break;
                        }                        if (i.Equals(120))
                        {
                            count = i;
                            break;
                        }
                        shopText.Append("<div class='t2'><ul class='shopUlList'><li><div class='t1'></div><img width='200px' src='/photo/200/" + modelList[i].Photolist.img + "'/></li></ul></div>");                    }                    shopText.Append("</div>");
                }
            }
我想在i为30  60 90 120的时候 跳到外面的for循环 但是我现在当i等于30的时候 跳出后i又被初始化成0了我想i继续往下走 就是i为31  这个怎么改 ? 

解决方案 »

  1.   

    break;跳出循环
    continue;结束本次循环
      

  2.   

    在加一个变量j就可以了。
    还有你这个Equals看起来真怪,用==吧,它只是值类型,能少写几个字符。int j = 0;
    for (int i = j; i < modelList.Count; i++,j++)
                        {
                            if (i.Equals(30))
                            {
                                count = i;
                                break;
                            }                        if (i.Equals(60))
                            {
                                count = i;
                                break;
                            }                        if (i.Equals(90))
                            {
                                count = i;
                                break;
                            }                        if (i.Equals(120))
                            {
                                count = i;
                                break;
                            }
      

  3.   


    StringBuilder shopText = new StringBuilder();
                List<Let.Model.ModelAllList> modelList = new Let.BLL.photoList().ExecuteReader(CommandType.StoredProcedure, "P_ShopList",
                       new SqlParameter("@startIndex", AspNetPager1.StartRecordIndex),
                       new SqlParameter("@endIndex", AspNetPager1.EndRecordIndex));            if (modelList.Count > 0)
                {
                    int count = 0;
                    int j=0;
                    for (int n = 0; n < 4; n++)
                    {
                        shopText.Append("<div class='divlist'>");                    for (int i = j; i < modelList.Count; i++)
                        {
                            if (i.Equals(30))
                            {
                                count = i;
                                j=31;
                                break;
                            }                        if (i.Equals(60))
                            {
                                count = i;
                                j=61;
                                break;
                            }                        if (i.Equals(90))
                            {
                                count = i;
                                j=91;
                                break;
                            }                        if (i.Equals(120))
                            {
                                count = i;
                                j=121;
                                break;
                            }
                            shopText.Append("<div class='t2'><ul class='shopUlList'><li><div class='t1'></div><img width='200px' src='/photo/200/" + modelList[i].Photolist.img + "'/></li></ul></div>");                    }                    shopText.Append("</div>");
                    }
                }
    没测试,自己测试一下看看