while循环中嵌套while循环,break退出分析

while (...)           //(1)
{
    while (...)       //(2)
         {....;
          break;}
    .....;
}

在上例中,break 退出只能退出里面的while,也就是退出(2)。


测试程序如下所示:

#include 
int main(void)
{
int i = 0;
int j = 1;
 while(i <= 2)
 {
      printf("i= %d\n",i);
      while(j <= 2)
        {
          if(j == 1)
           {
            printf("break  second while j =%d \n",j);
           
             break;
            } 
          if(j ==2 )
            {
             printf("ok ,continue while j=%d\n ",j);
             continue;
             }   
        
         j++; 
             }
      i++;
 }
 return 0;
}

 
  

输出结果为:

i = 0

break  second while j = 1

i = 1

ok ,continue while j= 2

i =2

你可能感兴趣的:(C++/C)