When you don't want to perform the action in the for statement for X element for whatever reason.
break will exit the loop completely, whereas continue just skips the element and carries on looping.
|
When you don't want to perform the action in the for statement for X element for whatever reason.
break will exit the loop completely, whereas continue just skips the element and carries on looping.
Ahh, that SORT of answers my question;
But I also need to know an example of a good time to use it, cause I've been over thinking this for like 10 minutes and I couldn't think of one method or ANYTHING that I could possibly use the continue statement for.
Quickest thing i could think of lol.Code:private void sendMessageToPlayer(String message) { for(Player p : Server.getPlayerHandler().players) { if(p == null || !p.isActive || p.disconnected) { continue; } p.sendMessage(message); } }
It's exactly the same as using
Code:private void sendMessageToPlayer(String message) { for(Player p : Server.getPlayerHandler().players) { if(p != null && p.isActive && !p.disconnected) { p.sendMessage(message); } } }
God damnit luke u stole my glory u fruit lol.
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |