Getting a JSLint warning concerning labels in Javascript

后端 未结 3 1978
余生分开走
余生分开走 2021-01-19 07:55

In my javascript I have this

    loopDeLoop:
        while (foo !== bar) {
            switch (fubar) {
                case reallyFubar:
                            


        
3条回答
  •  南笙
    南笙 (楼主)
    2021-01-19 08:14

    You could set a flag that determines whether or not you are done working in the loop.

    var done = false;
    while (foo !== bar && !done) {
        switch (fubar) {
            case reallyFubar:
                if (anotherFoo == anotherBar) {
                    done = true;
                }
                break;
    
            default:
                break;
        }
    
        if(!done) {
            //If you have more logic inside the loop, put it here
        }
    }
    

提交回复
热议问题