"if" statement requires an "else" at the end of it or no?

Discussion in 'Plugin Development' started by TheWayIRoll, Nov 9, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    TheWayIRoll

    Alright, so I have a scheduler task informing the server that it's running v0.0.0_01 and I have this syntax code.

    Code:java
    1.  
    2. this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    3. public void run() {
    4. if(config.getBoolean("general.broadcast_message", true)) {
    5. getServer().broadcastMessage(ChatColor.DARK_RED+"[Remine] Using v0.0.0_01. Disable this message in the config!");
    6. }
    7. }
    8. }, 18000L);
    9.  


    Will it be fine off without an "else" statement the end of the "if" statement, or will it be fine? I'm worrying right now.
     
  2. Offline

    DDoS

    Yes you'll be fine.

    Also, if you need java help, Google is great. This forum is more for Bukkit plugin dev help, and your question's topic is larger than that.
     
  3. Offline

    TheWayIRoll

    Thanks for your expertise to help me.

    Although, the scheduler is more Bukkit-related.

    P.S. I used the Wiki to pull this out. When I pasted it, I noticed a syntax error. So I registered on the wiki, and then fixed it.
     
  4. Offline

    Taco

    Just to clarify: An else statement tells what the program to do should the if statement not be met. Should the if statement be met, the else statement will not be read. A similar statement to this is else if, which is just another condition which will only be checked if the first condition isn't met. A simple if statement will always be checked.

    Example:
    Code:java
    1.  
    2. int condition = 1;
    3.  
    4. if(condition==1)
    5. {
    6. System.out.println(1);
    7. condition =2;
    8. }
    9. else if(condition==2)
    10. {
    11. System.out.println(2); //This will not be printed because the original if statement in this chain was met.
    12. condition=3;
    13. }
    14. else
    15. {
    16. System.out.println(3); //This will not be printed because the conditions of if statement previous to this was met.
    17. }
    18.  


    Code:java
    1.  
    2. int condition = 1;
    3.  
    4. if(condition==1)
    5. {
    6. System.out.println(1);
    7. condition =2;
    8. }
    9. if(condition==2)
    10. {
    11. System.out.println(2); //This WILL be printed because it's an independent if statement and we met the conditions before reaching it,.
    12.  
    13. condition=3;
    14. }
    15. else
    16. {
    17. System.out.println(3); //This will still not be printed because the conditions of if statement previous to this was met.
    18. condition =0;
    19. }
    20.  
     
Thread Status:
Not open for further replies.

Share This Page