Quantcast
Channel: User Federico klez Culloca - Stack Overflow
Viewing all articles
Browse latest Browse all 494

Answer by Federico klez Culloca for when using java return vs break

$
0
0

In this case it works because break exits the loop and goes to the end of the method which immediately returns. Which is functionally equivalent to returning immediately.

But in this case, for example

void run(){   while(true){    if(a>0){    }else{return;}  }  System.out.println("Hello");}

vs

void run(){   while(true){    if(a>0){    }else{break;}  }  System.out.println("Hello");}

The first version would not print, the second would


Viewing all articles
Browse latest Browse all 494

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>