为什么return之后的语句还能执行?

void bubbleSort1(int []a, int n)
{
int i,j,exchange;
int temp;
for(i=1;i<n;i++)
{
exchange=0;
for(j=0;j<n-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
exchange=1;
}

}
if(exchange==0)
return ;
}
for(int value:a)
System.out.println(value);

}

if(exchange==0)
 return ;//这句相当于
if(exchange==0){
    return ;
}
如果exchange不等于0,那么后面的for循环是会执行的。
如果exchange等于0,return才生效,后面的代码才不会执行

温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-04-10
有条件的,说明没有return。
第2个回答  2014-04-10
那就说明没有 return
相似回答