Java compilers or JVM languages that support goto?

前端 未结 9 2115
孤城傲影
孤城傲影 2021-01-12 20:22

Is there a java compiler flag that allows me to use goto as a valid construct? If not, are there any third-party java compilers that supports goto?

9条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-12 21:09

    Pretty much anything you can do with goto you can do with a loop. goto is really redundant and generally discredited way to program. IMHO.

    If you want to goto backwards

    LABEL: do {
    // code before goto
    
    // goto LABEL
    continue LABEL;
    
    // code after goto
    break;
    } while(true);
    

    If you want to goto forwards

    LABEL: do {
    // code before goto
    
    // goto LABEL
    continue LABEL;
    
    // code after goto
    break;
    } while(false);
    // Label is effectively here
    // code after LABEL.
    

提交回复
热议问题