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 22:05:27 +0100 Organization: A noiseless patient Spider Lines: 46 Message-ID: <87ftkhqwko.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> <87lfu9r1an.fsf@bsb.me.uk> <90de6262-942e-4ece-abcc-299b47f1a4c7@googlegroups.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="22298"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/8ocYCfC8XD9gTLpTzDLLj/pzPfLG92eE=" Cancel-Lock: sha1:hQALTmX2ISBzx6h6q3E8a5G6nCg= sha1:gJnrk013uDpmzHA9VOVH6eGnNt0= X-BSB-Auth: 1.1094f80f2927be803b57.20190927220527BST.87ftkhqwko.fsf@bsb.me.uk Xref: csiph.com comp.lang.javascript:37440 Jonas Thörnvall writes: > Den fredag 27 september 2019 kl. 21:23:35 UTC+2 skrev Ben Bacarisse: >> 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) { ... } This is not quite right, but there's not enough detail to be sure what you intended. You certainly don't need any loop when midiEv < nbrOfEV, but whether you need one when midiEv >= nbrOfEV is not clear. > I am not sure i think you missunderstood ask John he seem to > understand the element match and increment. I don't think you understand what John wrote. It looked to me like his answer was somewhat tongue-in-cheek. -- Ben.