Switch

Discussion in 'Plugin Development' started by dbizzzle, Nov 24, 2011.

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

    dbizzzle

    I am new to using switches (this is my first one I've ever attempted), could somebody please tell me if this is proper/will work?
    Code:java
    1.  
    2.  
    3. switch(3) {
    4. case 1:
    5. if (args.length == 0) {
    6. do something;
    7. }
    8. break;
    9.  
    10. case 2:
    11. if (args.length == 1) {
    12. do something;
    13. }
    14. break;
    15.  
    16. case 3:
    17. if (args.length > 1) {
    18. do something;
    19. }
    20. break;
    21. }
    22.  
     
  2. Offline

    Sagacious_Zed Bukkit Docs

    It works in the sense that it will always go to case 3.
     
  3. Offline

    dbizzzle

  4. Offline

    Sagacious_Zed Bukkit Docs

  5. Offline

    dbizzzle

    @Sagacious_Zed Thanks, I think I will just use else if though
     
  6. Offline

    Sagacious_Zed Bukkit Docs

    specifically in your case, you should replace the 3 inside the switch statement with args.length
     
  7. Offline

    Crash

    Try this :
    Code:
    switch(args.length){
        case 0://0 args
        {
            //...
        }
        break;
        case 1://1 arg
         {
            //...
        }
        break;
        default:// > 1 args
         {
            //...
        }
        break;
    }
     
  8. Offline

    dbizzzle

Thread Status:
Not open for further replies.

Share This Page