break_VS_continue

//date 2013 4 2
//designer :pengxiaoen
//function: look up the difference from break and continue

#include "stdio.h"
int main ()
{
int i,j,h,k;
//int i_for_break;j_for_continue;h_while_break;k_while_continue;

h = 0;k = 0;

for (i=0;i < 10;i++)
{
if (i>5) break;
printf ("i_for_break =%d\n",i);
}
printf ("the end i = %d",i);
printf("\n\n");

for (j=0;j<10;j++)
{
if (j>5) continue;
printf ("j_for_continue =%d\n",j);
}
printf ("the end j = %d",j);
printf("\n\n");

while (h!=10)
{
h++;
if(h == 5) break;
printf ("h_while_break = %d\n",h);
}
printf ("the end h = %d",h);
printf("\n\n");

while (k!=10)
{
k++;
if(k ==5) continue;
printf ("k_while_continue = %d\n",k);
}
printf ("the end k = %d",k);
printf("\n\n");

system ("pause");

}

 

结果:

结论:break 真的是“破'啊,破除了循环限制,彻底!!!

        continue 是表面的破除循环,终止本次循环,回到判断条件程序准备下一次循环,治标不治本的“跳出”循环。

posted on 2013-04-02 15:34  清霜一梦  阅读(170)  评论(0编辑  收藏  举报