Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.javascript Subject: Re: A proposition for a conditional loop. Date: Fri, 27 Sep 2019 20:23:28 +0100 Organization: A noiseless patient Spider Lines: 35 Message-ID: <87lfu9r1an.fsf@bsb.me.uk> References: <6e38ab46-bf8d-4422-9491-75019cc471fd@googlegroups.com> <9ee6c578-f5be-4d6c-97ca-dc63379641f6@googlegroups.com> <47bf83ce-1de3-4b9b-97bc-386d7b306f0a@googlegroups.com> <95dfed9c-f232-43d4-aa54-267e5fa87115@googlegroups.com> <76kroehhtucq3t3v7s7ogtve762f1sf9eo@4ax.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Injection-Info: reader02.eternal-september.org; posting-host="1cc2abe73623ffa0dd34b6aaf8be2fa8"; logging-data="18687"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+9/bVJHlLjWpkZlYWLTKaxpDu0we1zZ6Y=" Cancel-Lock: sha1:Kvi5EALYfDQmTI0uocflExmJfZ8= sha1:uSHQ/hZro9owCWTgWbdiwIIVEBc= X-BSB-Auth: 1.9afddd165c53bfe4b935.20190927202328BST.87lfu9r1an.fsf@bsb.me.uk Xref: csiph.com comp.lang.javascript:37437 Jonas Thörnvall writes: > compare with > > while(z if(track[rectrack].midiMess[z].data1==track[rectrack].midiMess[midiEv].data1){ > ctm.fillStyle = "#000a4d"; > ctm.fillRect(scrollBarPos-BACKOFFSET[midiEv]-5,(PistartX+keyHeight*88)-(keyHeight*(track[rectrack].midiMess[midiEv].data1-8))-1,barLength[midiEv]+50 ,keyHeight+2); > ctm.fillStyle = pcolor[track[rectrack].midiMess[midiEv].data1]; > ctm.fillRect(scrollBarPos-BACKOFFSET[midiEv],(PistartX+keyHeight*88)-(keyHeight*(track[rectrack].midiMess[midiEv].data1-8)), barLength[midiEv]+50,keyHeight); > > break; > } > z++; > } > } One way to do a search for an element is with Array.prototype.find or similar, but the logic of your example looks very odd, so this soer of search may not be what you are really doing. The odd part is that the block of code does not use the element found but the one being tested against. If midiEv is < nbrOfEV, then a matching z certainly will be found. It might be some z < midiEv but it will be no later than when z == midiEv. But in both cases (z < midiEv and z == midiEv), the body of the 'if' does the same thing. So, provided z starts at 0, you are really only testing if (midiEv < nbrOfEV) { ... } Whats more, if nbrOfEV is what is sounds like (the size of the array) then that test will always be true and you don't need any of this code. -- Ben.