Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.javascript Subject: Re: Logic problem, i always had problem translate until statements into while Date: Fri, 27 Jan 2017 11:02:43 +0000 Organization: A noiseless patient Spider Lines: 69 Message-ID: <87k29gzrxo.fsf@bsb.me.uk> References: <7112e5ec-cc6f-4b7b-b7db-b83b52bf8fbe@googlegroups.com> <87inp11s6w.fsf@bsb.me.uk> <36a74771-51d8-439a-bd1a-0c7338031b9c@googlegroups.com> <10dc87b2-3078-4b1d-a914-0461db1c80a6@googlegroups.com> <87sho5zaj9.fsf@bsb.me.uk> <74b7c25f-9f8f-4bc5-8380-9cb6e6e8bd1e@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="3b591314b8affd39d0054b2ccd164f7b"; logging-data="17052"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19DvxfvVgME9hAp4sHI+MP52yRSV6fupQk=" Cancel-Lock: sha1:DWNKejWjikNoMvS9AnYUZey3Dfc= sha1:yf0vGaQnVN24PsF+IljIA9kMIsA= X-BSB-Auth: 1.4cdf5e69d522c032dc67.20170127110243GMT.87k29gzrxo.fsf@bsb.me.uk Xref: csiph.com comp.lang.javascript:32372 jonas.thornvall@gmail.com writes: > Den fredag 27 januari 2017 kl. 00:06:24 UTC+1 skrev Ben Bacarisse: >> jonas.thornvall@gmail.com writes: >> >> > Den torsdag 26 januari 2017 kl. 22:24:32 UTC+1 skrev jonas.t...@gmail.com: >> >> Den torsdag 26 januari 2017 kl. 21:29:05 UTC+1 skrev Ben Bacarisse: >> >> > jonas.thornvall@gmail.com writes: >> >> > >> >> > > do until (regular == true && connected == false ) >> >> > > >> >> > > I honestly feel a bit lost, because i think they are so easy to code >> >> > > using do until. >> >> > >> >> > What as the initial values of 'regular' and 'connected'? >> >> > >> >> > > So how should i think about it? >> >> > >> >> > Provided the initial value of the resulting while condition is true you >> >> > just need to invert it: >> >> > >> >> > while (!(regular == true && connected == false)) ... >> >> > >> >> > You can use De Morgan's laws to simplify that if you like: >> >> > >> >> > !(A && B) <=> !A || !B >> >> > !(A || B) <=> !A && !B >> >> > >> >> > in your case >> >> > >> >> > !(regular == true && connected == false) >> >> > => !(regular == true) || !(connected == false) >> >> > => regular != true || connected != false >> >> > >> >> > which I'd just write as >> >> > >> >> > while (!regular || connected) ... >> >> > >> >> > Often, the use of do ... until is simply an error (while is needed more >> >> > often in algorithms than do...until). In those cases there is no need >> >> > for the loop to execute at least once and you don't need to check that >> >> > '!regular || connected' is initially true. >> >> > >> >> > -- >> >> > Ben. >> >> >> >> Unfortunately they are both false, >> >> Why is that unfortunate? If they are both initially false your >> do...until can be written as a while with the condition negated. >> >> >> -- >> Ben. > > I feel you dodged the obstacle, Probably. > i asked if the boolean is > generated/searched and found within loop and all values of the truth > table can be found, how do you set the start condition, can i set the > boolean to "null" at start? If you asked this I missed it, but I couldn't answer it anyway because I don't know what it means. -- Ben.