Java Loop Efficiency. if-continue OR if -


the question being thought today while completing task loop efficiency..

lets say. have array {'a','x','a','a'} , loop should avoid 'x' element wonder how these 2 approach differ in term of efficiency - not taking while or do-while or loops differentiation

char[] arrexample = {'a','x','a','a'}; for(int idx = 0; idx<arrexample.length; idx++){     if(arrexample[idx] == 'x')         continue;      system.out.println(arrexample[idx]); } 

and common loop this

char[] arrexample = {'a','x','a','a'}; for(int idx = 0; idx<arrexample.length; idx++){     if(arrexample[idx] != 'x')         system.out.println(arrexample[idx]); } 

so.. expert comments pleased. thanks!

even if went nonoptimized byte-code, identical. there's 2 real differences. first placement of jump statement, jump statement still executed same number of times. also, == , != operators both atomic operator, taking same amount of time execute both.

as said before, use whatever makes sense you. i'd have admit, continue statement version rather awkward read.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -