zoukankan      html  css  js  c++  java
  • 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 是表面的破除循环,终止本次循环,回到判断条件程序准备下一次循环,治标不治本的“跳出”循环。

  • 相关阅读:
    机器人
    仙岛求药(一)
    YZM 二分查找
    珠心算测验升级版
    博客正在施工
    【其他】16年12月博客阅读索引^_^
    博客有新家了!
    POJ No.3617【B008】
    POJ No.2386【B007】
    【刷题记录】部分和问题
  • 原文地址:https://www.cnblogs.com/sepeng/p/2995606.html
Copyright © 2011-2022 走看看