break和continue的区别和作用

224 阅读1分钟
  1. break
    	var str = "hello";
        for (var item of str){
            if(item ==="l"){
                break
            }
            console.log(item);  // h e 
        }
    
  2. continue
    	var str = "hello";
        for (var item of str){
            if(item ==="l"){
                continue
            }
            console.log(item);  // h e o
        }
    

3.总结的话:continue和break区别在于continue只是终止当前循环,接着还执行后面的循环,break则完全终止循环,跳出循环体执行循环后面的语句。