Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
220 views
in Technique[技术] by (71.8m points)

javascript - Which is a more efficient way to use the If Condition?

I am using the IF condition inside a for loop. I have two way to do that :

1. I can use IF-Continue

for(let i=0;i<10;i++){
if(i%2==0) {
//doing some stuff
continue
}
console.log(i)
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There's no difference in how the code works or which one is quicker. continue is basically the same as putting everything below in else.

What I do is: If you are doing something similar, I would use if/else. If what you are doing is conceptually different I would use the continue example.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...