Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Arno Welzel Newsgroups: comp.lang.javascript Subject: Re: boolean while loops "how to stop" and "make room for textout to textarea" Date: Sat, 31 Oct 2020 18:49:27 +0100 Lines: 61 Message-ID: References: <6d2d33cc-9b19-469c-a25c-d8d2f862f0aco@googlegroups.com> <314f637c-5652-49f0-b79c-356f95244328o@googlegroups.com> <2397252d-ca36-4e93-8d73-88816bf4fabeo@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: individual.net pm0UtCS3Ig+fR1fMmW8V2gva1BuYAfNlVm4g0Ieu3ve7tLgtLQ Cancel-Lock: sha1:UkGbRyh33oE20A0Y9jDoY5/Ncv4= In-Reply-To: <2397252d-ca36-4e93-8d73-88816bf4fabeo@googlegroups.com> Xref: csiph.com comp.lang.javascript:39064 Jonas Thörnvall: > Den lördag 31 oktober 2020 kl. 14:08:00 UTC+1 skrev Julio Di Egidio: >> On Saturday, 31 October 2020 12:20:44 UTC+1, Jonas Thörnvall wrote: >>> Den lördag 31 oktober 2020 kl. 11:44:43 UTC+1 skrev Jonas Thörnvall: >>>> When creating a while loop like this. >>>> while(run==true){ >>>> >>>> } >>>> >>>> 1. How can i stop it, i tried a button that call function that set run=false but that do not work. >>>> >>>> 2. How can i write out values to textarea while still in loop, it does not seem "to have time" want to do it until loop breaks? >>> >>> >> >> Your code is a complete mess! >> >> Here is a working version, for the fun of it: >> [...] > So again Julio, instead of point to code that obviously flawed in some functional way. This code is OK. You just don't understand it. > 1. Why does this loop not stop when stop button pushed? It does. > The syntax tell it to do so but apparently Javascript or dome doesn't care. Why do you think so? When I run the example above in Firefox or Chrome it works fine. I click "Run" and the loop starts and when I click "Stop", it will stop again. > 2. Whey does it not write out value to textfield as the syntax tell, but apparently Javascript do not give a shit about syntactical order of the things to do. It does. You just don't understand how JavaScript works in a Browser. [...] > while (run==true){ [...] > } [...] > function stop(){ > run=false; > } [...] > Just creating a loop which never exists as long as "run" is not false does not work if this should be something useful in the browser. That's the reason where there are functions like setTimeout() or setInterval() to keep things running in JavaScript while still being able to handle events caused by the user. -- Arno Welzel https://arnowelzel.de