abt嵌套循环 [英] abt nested loops
问题描述
嗨
i有两个嵌套循环,如下所示:
1.
for(i = 0; i< = 1000; i ++ )
{
for(i = 0; i< = 100; i ++)
{
.. ...;
.....;
}
}
等一个是
2.
for(i = 0; i< = 100; i ++)
{
for(i = 0; i< = 1000; i ++)
{
.....;
.....;
}
}
所以我的问题是哪个循环在性能方面最好..请
评论为什么会这样..
我觉得第二循环在性能方面是最好的。
问候''
Pavan
Pavan写道:
你好
我有两个嵌套循环,如下所示:
1.
for(i = 0; i< = 1000; i ++)
{
for(i = 0; i< = 100 ; i ++)
{
.....;
.....;
}
}
和ot她的一个是
2.
for(i = 0; i< = 100; i ++)
{
for(i = 0; i< = 1000; i ++)
{
.....;
.....;
}
}
所以我的问题是哪个循环最好性能方面。请注意为什么会如此...
我觉得第二循环在性能方面是最好的。
2nd循环停止。
第一个循环没有。
-
pete
你好Pete
thx回复..我很害怕,我没有得到你!!
为什么第二个循环停止和哪里它停止
请清楚
欢呼
Pavan
Pavan写道:
你好Pete
thx回复..我很害怕,我没有得到你!!
为什么第二个循环停止并停在哪里
请清楚
2.
for( i = 0; i <= 100; i ++)
/ *首先,我等于0 * /
{
for(i = 0; i< = 1000; i ++ )
{
.....;
.....;
}
/ *
**秒,我等于1001,
**外循环停止,因为我> 100
* /
}
-
pete
Hi
i have two nested loops as shown below:
1.
for(i=0;i<=1000;i++)
{
for(i=0;i<=100;i++)
{
.....;
.....;
}
}
and other one is
2.
for(i=0;i<=100;i++)
{
for(i=0;i<=1000;i++)
{
.....;
.....;
}
}
so my question is which loop is best in terms of performance..please
comment why is it so ..
what i feel is 2nd loop is best in performance wise.
Regards''
Pavan
Pavan wrote:
Hi
i have two nested loops as shown below:
1.
for(i=0;i<=1000;i++)
{
for(i=0;i<=100;i++)
{
.....;
.....;
}
}
and other one is
2.
for(i=0;i<=100;i++)
{
for(i=0;i<=1000;i++)
{
.....;
.....;
}
}
so my question is which loop is best in terms of performance..please
comment why is it so ..
what i feel is 2nd loop is best in performance wise.
2nd loop stops.
1st loop doesn''t.
--
pete
Hi Pete
thx for replying ..i am afraid ,, i did''t get you !!
why does 2nd loops stops and where it stops
please be clear
cheers
Pavan
Pavan wrote:
Hi Pete
thx for replying ..i am afraid ,, i did''t get you !!
why does 2nd loops stops and where it stops
please be clear
2.
for(i=0;i<=100;i++)
/* first, i equals 0 */
{
for(i=0;i<=1000;i++)
{
.....;
.....;
}
/*
** second, i equals 1001,
** outer loop stops because i > 100
*/
}
--
pete
这篇关于abt嵌套循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!