Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #39053 > unrolled thread
| Started by | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| First post | 2020-10-31 03:44 -0700 |
| Last post | 2020-11-03 17:28 -0800 |
| Articles | 20 on this page of 34 — 6 participants |
Back to article view | Back to comp.lang.javascript
boolean while loops "how to stop" and "make room for textout to textarea" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-10-31 03:44 -0700
Re: boolean while loops "how to stop" and "make room for textout to textarea" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-10-31 04:20 -0700
Re: boolean while loops "how to stop" and "make room for textout to textarea" Julio Di Egidio <julio@diegidio.name> - 2020-10-31 06:07 -0700
Re: boolean while loops "how to stop" and "make room for textout to textarea" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-10-31 09:41 -0700
Re: boolean while loops "how to stop" and "make room for textout to textarea" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-10-31 09:45 -0700
Re: boolean while loops "how to stop" and "make room for textout to textarea" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-10-31 09:48 -0700
Re: boolean while loops "how to stop" and "make room for textout to textarea" Julio Di Egidio <julio@diegidio.name> - 2020-10-31 10:10 -0700
Re: boolean while loops "how to stop" and "make room for textout to textarea" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-10-31 10:42 -0700
Re: boolean while loops "how to stop" and "make room for textout to textarea" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-10-31 10:05 -0700
Re: boolean while loops "how to stop" and "make room for textout to textarea" Arno Welzel <usenet@arnowelzel.de> - 2020-10-31 18:49 +0100
Re: boolean while loops "how to stop" and "make room for textout to textarea" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-10-31 11:07 -0700
Re: boolean while loops "how to stop" and "make room for textout to textarea" John G Harris <niam@jghnorth.org.uk.invalid> - 2020-11-01 11:39 +0000
Re: boolean while loops "how to stop" and "make room for textout to textarea" Arno Welzel <usenet@arnowelzel.de> - 2020-11-01 13:52 +0100
Re: boolean while loops "how to stop" and "make room for textout to textarea" Julio Di Egidio <julio@diegidio.name> - 2020-11-01 21:57 -0800
Re: boolean while loops "how to stop" and "make room for textout to textarea" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-11-01 23:44 -0800
Re: boolean while loops "how to stop" and "make room for textout to textarea" Arno Welzel <usenet@arnowelzel.de> - 2020-10-31 18:24 +0100
Re: boolean while loops "how to stop" and "make room for textout to textarea" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-10-31 10:44 -0700
Re: boolean while loops "how to stop" and "make room for textout to textarea" Arno Welzel <usenet@arnowelzel.de> - 2020-10-31 18:52 +0100
Re: boolean while loops "how to stop" and "make room for textout to textarea" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-10-31 11:14 -0700
Re: boolean while loops "how to stop" and "make room for textout to textarea" John G Harris <niam@jghnorth.org.uk.invalid> - 2020-11-01 11:45 +0000
Re: boolean while loops "how to stop" and "make room for textout to textarea" Arno Welzel <usenet@arnowelzel.de> - 2020-11-01 14:02 +0100
Re: boolean while loops "how to stop" and "make room for textout to textarea" John G Harris <niam@jghnorth.org.uk.invalid> - 2020-11-01 17:38 +0000
Re: boolean while loops "how to stop" and "make room for textout to textarea" Arno Welzel <usenet@arnowelzel.de> - 2020-11-01 21:07 +0100
Re: boolean while loops "how to stop" and "make room for textout to textarea" John G Harris <niam@jghnorth.org.uk.invalid> - 2020-11-02 19:36 +0000
Re: boolean while loops "how to stop" and "make room for textout to textarea" Arno Welzel <usenet@arnowelzel.de> - 2020-11-03 18:34 +0100
Re: boolean while loops "how to stop" and "make room for textout to textarea" Julio Di Egidio <julio@diegidio.name> - 2020-11-03 11:48 -0800
Re: boolean while loops "how to stop" and "make room for textout to textarea" Arno Welzel <usenet@arnowelzel.de> - 2020-11-04 15:17 +0100
Re: boolean while loops "how to stop" and "make room for textout to textarea" Arno Welzel <usenet@arnowelzel.de> - 2020-11-04 15:18 +0100
Re: boolean while loops "how to stop" and "make room for textout to textarea" Julio Di Egidio <julio@diegidio.name> - 2020-11-04 12:52 -0800
Re: boolean while loops "how to stop" and "make room for textout to textarea" Arno Welzel <usenet@arnowelzel.de> - 2020-11-05 16:12 +0100
Re: boolean while loops "how to stop" and "make room for textout to textarea" Arno Welzel <usenet@arnowelzel.de> - 2020-11-01 14:02 +0100
Re: boolean while loops "how to stop" and "make room for textout to textarea" "sc...@sauyet.com" <scott@sauyet.com> - 2020-11-03 13:27 -0800
Re: boolean while loops "how to stop" and "make room for textout to textarea" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-11-03 14:08 -0800
Re: boolean while loops "how to stop" and "make room for textout to textarea" Scott Sauyet <scott.sauyet@gmail.com> - 2020-11-03 17:28 -0800
Page 1 of 2 [1] 2 Next page →
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2020-10-31 03:44 -0700 |
| Subject | boolean while loops "how to stop" and "make room for textout to textarea" |
| Message-ID | <6d2d33cc-9b19-469c-a25c-d8d2f862f0aco@googlegroups.com> |
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?
[toc] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2020-10-31 04:20 -0700 |
| Message-ID | <ba111515-c079-49bc-939b-bdc8eaf5279ao@googlegroups.com> |
| In reply to | #39053 |
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?
<HEAD>
<script>
var run=false;
function getRandomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}
//Head = 1 Tail = 0
function streaks(){
j=0;
streak=0;consecutive=0;
document.getElementById("textout").value="***WAIT***/n";
choice=document.getElementById("mychoice").value;
run=true;
if (choice=="head"){
while (j<1000000000){
myval=getRandomInt(2);
if(myval==1){
//alert(consecutive);
consecutive=consecutive+1;
} else {
//alert("CONSECUTIVE "+consecutive+" STREAK "+streak);
if (consecutive>streak){
mytext="TRY "+j+" STREAK "+choice+" "+consecutive+"\n";
streak=consecutive;
document.getElementById("textout").value+=mytext;
//console.log(document.getElementById("textout").value);
}
consecutive=0;
}
j++;
}
} else if (choice=="tail"){
while (j<10000){
myval=getRandomInt(2);
if(myval==0){
consecutive=consecutive+1;
} else {
if (consecutive>streak){
mytext="Try "+j+" Consecutive "+choice+" "+consecutive+"\n";
streak=consecutive;
document.getElementById("textout").value+=mytext;
//console.log(document.getElementById("textout").value);
}
consecutive=0;
}
j++;
}
}
}
function stop(){
run=false;
}
</script>
</HEAD>
<h2>STATISTICAL OUTCOME **STREAKS** WHEN FLIPPING COINS</h2>
<BODY BGCOLOR="YELLOW">
<B>CONSECUTIVE COIN FLOPS | SELECT</B>
<select name="mychoice" id="mychoice">
<option value="head">HEADS</option>
<option value="tail">TAILS</option>
</select>
<BR>
<textarea id="textout" name="textout" rows="20" cols="50"></textarea><BR>
<button onclick="streaks()">START COINFLIP</button> <button onclick="stop()">STOP FLIP</button>
</BODY>
</HTML>
[toc] | [prev] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2020-10-31 06:07 -0700 |
| Message-ID | <314f637c-5652-49f0-b79c-356f95244328o@googlegroups.com> |
| In reply to | #39054 |
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?
>
> <snipped disaster zone>
Your code is a complete mess!
Here is a working version, for the fun of it:
<https://codepen.io/jp-diegidio/pen/mdExgZe>
Notice not just how to write that loop logic but also
how *the logic is separate from the rendering*, and,
more generally, *the use of functions* not only to
partition the code, but also, in conjunction with a
decent naming, to make it *dramatically* more readable
and manageable. Code must speak (must be readable)!
Your sloppiness and lack of any I won't say discipline
but even raw passion is appalling...
Julio
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2020-10-31 09:41 -0700 |
| Message-ID | <68e05a2a-330a-43db-ac8c-963f7eeaac21o@googlegroups.com> |
| In reply to | #39055 |
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?
> >
> > <snipped disaster zone>
>
> Your code is a complete mess!
>
> Here is a working version, for the fun of it:
> <https://codepen.io/jp-diegidio/pen/mdExgZe>
>
> Notice not just how to write that loop logic but also
> how *the logic is separate from the rendering*, and,
> more generally, *the use of functions* not only to
> partition the code, but also, in conjunction with a
> decent naming, to make it *dramatically* more readable
> and manageable. Code must speak (must be readable)!
>
> Your sloppiness and lack of any I won't say discipline
> but even raw passion is appalling...
>
> Julio
Well apparently what he does is fucking slow. I just want a way to break loop and a way to timeout for write value. I think his code broken it is way to slow to be useful.
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2020-10-31 09:45 -0700 |
| Message-ID | <f297044b-e529-4e86-ab7e-c58f2733d332o@googlegroups.com> |
| In reply to | #39055 |
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?
> >
> > <snipped disaster zone>
>
> Your code is a complete mess!
>
> Here is a working version, for the fun of it:
> <https://codepen.io/jp-diegidio/pen/mdExgZe>
>
> Notice not just how to write that loop logic but also
> how *the logic is separate from the rendering*, and,
> more generally, *the use of functions* not only to
> partition the code, but also, in conjunction with a
> decent naming, to make it *dramatically* more readable
> and manageable. Code must speak (must be readable)!
>
> Your sloppiness and lack of any I won't say discipline
> but even raw passion is appalling...
>
> Julio
I threw together my code in some 30 minutes, so it is not like i put time into it. But the structure is sound, now tell me howto break a while loop because apparently it will not break by setting run to false from UI.
And please tell me howto write out "timeout" loop to write to textarea.
No i think my structure make sense, what does not make sense is javascript not able to handle booleans used in loops and not able to timeout loops to write out values. That is my opinion about what is flawed, although your may difer.
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2020-10-31 09:48 -0700 |
| Message-ID | <c2c3b139-0218-4d12-b8f6-71494104af70o@googlegroups.com> |
| In reply to | #39055 |
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?
> >
> > <snipped disaster zone>
>
> Your code is a complete mess!
>
> Here is a working version, for the fun of it:
> <https://codepen.io/jp-diegidio/pen/mdExgZe>
>
> Notice not just how to write that loop logic but also
> how *the logic is separate from the rendering*, and,
> more generally, *the use of functions* not only to
> partition the code, but also, in conjunction with a
> decent naming, to make it *dramatically* more readable
> and manageable. Code must speak (must be readable)!
>
> Your sloppiness and lack of any I won't say discipline
> but even raw passion is appalling...
>
> Julio
How do you think one will plot the data wnen the moron do not even write out in which iteration the streak occured, and why so slow????
[toc] | [prev] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2020-10-31 10:10 -0700 |
| Message-ID | <fd3aaec8-f010-4214-84b7-e451e79e6ae0o@googlegroups.com> |
| In reply to | #39058 |
On Saturday, 31 October 2020 17:48:22 UTC+1, Jonas Thörnvall wrote:
> 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?
> > >
> > > <snipped disaster zone>
> >
> > Your code is a complete mess!
> >
> > Here is a working version, for the fun of it:
> > <https://codepen.io/jp-diegidio/pen/mdExgZe>
> >
> > Notice not just how to write that loop logic but also
> > how *the logic is separate from the rendering*, and,
> > more generally, *the use of functions* not only to
> > partition the code, but also, in conjunction with a
> > decent naming, to make it *dramatically* more readable
> > and manageable. Code must speak (must be readable)!
> >
> > Your sloppiness and lack of any I won't say discipline
> > but even raw passion is appalling...
>
> How do you think one will plot the data wnen the moron do not even write out in which iteration the streak occured, and why so slow????
The script runs pretty much "bare metal", just you do not
know what your own intensions are: that it prints out only
streaks that are longer than already found. You'll have to
change it if you want it to do something else: hopefully
with an eye as to how to write better code, as that was the
main point.
Anyway, if you want to see the single streaks, you can hack
easily into it as so:
Change:
if (streak > _max_streak) {
to:
if (true || streak > _max_streak) { // always true
And better also change few lines later:
_timer = window.setTimeout(run, 0);
to:
_timer = window.setTimeout(run, 250);
Julio
P.S. The flaw is your listening impairment...
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2020-10-31 10:42 -0700 |
| Message-ID | <a3e4095f-dc14-473f-90bc-39937fa6cb1fo@googlegroups.com> |
| In reply to | #39060 |
Den lördag 31 oktober 2020 kl. 18:10:10 UTC+1 skrev Julio Di Egidio:
> On Saturday, 31 October 2020 17:48:22 UTC+1, Jonas Thörnvall wrote:
> > 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?
> > > >
> > > > <snipped disaster zone>
> > >
> > > Your code is a complete mess!
> > >
> > > Here is a working version, for the fun of it:
> > > <https://codepen.io/jp-diegidio/pen/mdExgZe>
> > >
> > > Notice not just how to write that loop logic but also
> > > how *the logic is separate from the rendering*, and,
> > > more generally, *the use of functions* not only to
> > > partition the code, but also, in conjunction with a
> > > decent naming, to make it *dramatically* more readable
> > > and manageable. Code must speak (must be readable)!
> > >
> > > Your sloppiness and lack of any I won't say discipline
> > > but even raw passion is appalling...
> >
> > How do you think one will plot the data wnen the moron do not even write out in which iteration the streak occured, and why so slow????
>
> The script runs pretty much "bare metal", just you do not
> know what your own intensions are: that it prints out only
> streaks that are longer than already found. You'll have to
> change it if you want it to do something else: hopefully
> with an eye as to how to write better code, as that was the
> main point.
>
> Anyway, if you want to see the single streaks, you can hack
> easily into it as so:
>
> Change:
> if (streak > _max_streak) {
> to:
> if (true || streak > _max_streak) { // always true
>
> And better also change few lines later:
> _timer = window.setTimeout(run, 0);
> to:
> _timer = window.setTimeout(run, 250);
>
> Julio
>
> P.S. The flaw is your listening impairment...
No that is wrong Julio my intentions are per the code as if it were executed as such. But it is not apparently Javascript and its connection to both dome and other functions goes into lockdown mode. My code work perfectly well if i set the limit to 1 billion iteration and it comes out around 30 in max streak as expected in some 15-20 sec. The code you presented do not seem to know what it is doing and is slow beyond anything really useful, being pretty isn't the main objective, being logical and fast is much better.
And you still not answered howto change my code. If i want a subset of the streaks using a billion j iterations plotted i just move values to array.
And plot them out afterwards, however plot out the 30 values or so would be nice to do as they are found, so one know the script have not timed out.
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2020-10-31 10:05 -0700 |
| Message-ID | <2397252d-ca36-4e93-8d73-88816bf4fabeo@googlegroups.com> |
| In reply to | #39055 |
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?
> >
> > <snipped disaster zone>
>
> Your code is a complete mess!
>
> Here is a working version, for the fun of it:
> <https://codepen.io/jp-diegidio/pen/mdExgZe>
>
> Notice not just how to write that loop logic but also
> how *the logic is separate from the rendering*, and,
> more generally, *the use of functions* not only to
> partition the code, but also, in conjunction with a
> decent naming, to make it *dramatically* more readable
> and manageable. Code must speak (must be readable)!
>
> Your sloppiness and lack of any I won't say discipline
> but even raw passion is appalling...
>
> Julio
So again Julio, instead of point to code that obviously flawed in some functional way.
1. Why does this loop not stop when stop button pushed?
The syntax tell it to do so but apparently Javascript or dome doesn't care.
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.
<HTML>
<HEAD>
<script>
var run=false;
function getRandomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}
//Head = 1 Tail = 0
function streaks(){
j=0;
streak=0;consecutive=0;
document.getElementById("textout").value="***WAIT***/n";
choice=document.getElementById("mychoice").value;
run=true;
if (choice=="head"){
//while (j<1000000000){
while (run==true){
myval=getRandomInt(2);
if(myval==1){
//alert(consecutive);
consecutive=consecutive+1;
} else {
//alert("CONSECUTIVE "+consecutive+" STREAK "+streak);
if (consecutive>streak){
mytext="TRY "+j+" STREAK "+choice+" "+consecutive+"\n";
streak=consecutive;
document.getElementById("textout").value+=mytext;
//console.log(document.getElementById("textout").value);
}
consecutive=0;
}
j++;
}
} else if (choice=="tail"){
//while (j<1000000000){
while (run==true){
myval=getRandomInt(2);
if(myval==0){
consecutive=consecutive+1;
} else {
if (consecutive>streak){
mytext="Try "+j+" Consecutive "+choice+" "+consecutive+"\n";
streak=consecutive;
document.getElementById("textout").value+=mytext;
//console.log(document.getElementById("textout").value);
}
consecutive=0;
}
j++;
}
}
}
function stop(){
run=false;
}
</script>
</HEAD>
<h2>STATISTICAL OUTCOME **STREAKS** WHEN FLIPPING COINS</h2>
<BODY BGCOLOR="YELLOW">
<B>CONSECUTIVE COIN FLOPS | SELECT</B>
<select name="mychoice" id="mychoice">
<option value="head">HEADS</option>
<option value="tail">TAILS</option>
</select>
<BR>
<textarea id="textout" name="textout" rows="20" cols="50"></textarea><BR>
<button onclick="streaks()">START COINFLIP</button> <button onclick="stop()">STOP FLIP</button>
</BODY>
</HTML>
[toc] | [prev] | [next] | [standalone]
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Date | 2020-10-31 18:49 +0100 |
| Subject | Re: boolean while loops "how to stop" and "make room for textout to textarea" |
| Message-ID | <i05md7F71etU1@mid.individual.net> |
| In reply to | #39059 |
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?
>>>
>>> <snipped disaster zone>
>>
>> Your code is a complete mess!
>>
>> Here is a working version, for the fun of it:
>> <https://codepen.io/jp-diegidio/pen/mdExgZe>
[...]
> 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;
> }
[...]
> <button onclick="streaks()">START COINFLIP</button> <button onclick="stop()">STOP FLIP</button>
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
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2020-10-31 11:07 -0700 |
| Subject | Re: boolean while loops "how to stop" and "make room for textout to textarea" |
| Message-ID | <72ba1be0-524c-4f9b-aef7-4bae15ab7f20o@googlegroups.com> |
| In reply to | #39064 |
Den lördag 31 oktober 2020 kl. 18:49:37 UTC+1 skrev Arno Welzel:
> 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?
> >>>
> >>> <snipped disaster zone>
> >>
> >> Your code is a complete mess!
> >>
> >> Here is a working version, for the fun of it:
> >> <https://codepen.io/jp-diegidio/pen/mdExgZe>
> [...]
> > 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;
> > }
> [...]
> > <button onclick="streaks()">START COINFLIP</button> <button onclick="stop()">STOP FLIP</button>
>
> 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
No you are so wrong Arno, a programming language ***must*** be able to handle.
Letting UI set a boolean to stop a loop, javascripts idea of invent idiot syntax to replace the obvious, is so incredible stupid it must been invented by an ENTP.
while (run==true){}
And then from UI call a function to set the run boolean false, is how things should work ***anything else is just nonesense, making no sense***. There is nothing wrong with setInterval and setTimout. But they fucking should not replace set the boolean to false.
function stop(){run false}
<button onClick="stop()">YEAH THIS ***SHOULD*** BE DEFAULT SYNTAX AND IS IN MOST LANGUAGES?????</button>
And why the fuck anyone would like to set a timeOut instead then change the boolean in this case is beyond my comprehension...... It is so fucking stupid.
[toc] | [prev] | [next] | [standalone]
| From | John G Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2020-11-01 11:39 +0000 |
| Subject | Re: boolean while loops "how to stop" and "make room for textout to textarea" |
| Message-ID | <4j7tpflesohge0kupc3flsvqfh6i30msus@4ax.com> |
| In reply to | #39066 |
On Sat, 31 Oct 2020 11:07:27 -0700 (PDT), Jonas Thörnvall
<jonas.thornvall@gmail.com> wrote:
<snip>
>
>No you are so wrong Arno, a programming language ***must*** be able to handle.
>
>Letting UI set a boolean to stop a loop, javascripts idea of invent idiot syntax to replace the obvious, is so incredible stupid it must been invented by an ENTP.
>
>while (run==true){}
>
>And then from UI call a function to set the run boolean false, is how things should work ***anything else is just nonesense, making no sense***. There is nothing wrong with setInterval and setTimout. But they fucking should not replace set the boolean to false.
>
>function stop(){run false}
>
><button onClick="stop()">YEAH THIS ***SHOULD*** BE DEFAULT SYNTAX AND IS IN MOST LANGUAGES?????</button>
>
>And why the fuck anyone would like to set a timeOut instead then change the boolean in this case is beyond my comprehension...... It is so fucking stupid.
Microsoft Windows does not allow application programs to supply
interrupt code. The code you show above won't work in a Windows PC
even if your program is written in binary.
Blaming ECMAScript 'syntax' for this is foolish.
John
[toc] | [prev] | [next] | [standalone]
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Date | 2020-11-01 13:52 +0100 |
| Subject | Re: boolean while loops "how to stop" and "make room for textout to textarea" |
| Message-ID | <i07pd3Fk95bU1@mid.individual.net> |
| In reply to | #39066 |
Jonas Thörnvall:
> Den lördag 31 oktober 2020 kl. 18:49:37 UTC+1 skrev Arno Welzel:
[...]
>> 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
>
> No you are so wrong Arno, a programming language ***must*** be able to handle.
The language has nothing to do with it. I am talking about how a UI and
multithreading works in general. If there is only one thread there is no
way to handle UI events as long as the thread is inside a while() loop.
Do you even know, what threads in software are?
> Letting UI set a boolean to stop a loop, javascripts idea of invent idiot syntax to replace the obvious, is so incredible stupid it must been invented by an ENTP.
The click event WILL NOT be handled, as long as your code is still
inside a loop!
> while (run==true){}
>
> And then from UI call a function to set the run boolean false, is how things should work ***anything else is just nonesense, making no sense***. There is nothing wrong with setInterval and setTimout. But they fucking should not replace set the boolean to false.
The problem is, that the click handler will not be called as long as
your code is inside the while() loop because there is only one thread
which either runs your code OR handles UI events.
Please try at least to learn what multithreading and event handling means.
--
Arno Welzel
https://arnowelzel.de
[toc] | [prev] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2020-11-01 21:57 -0800 |
| Message-ID | <9755e237-2a18-43f2-95ed-f1e7f44baadao@googlegroups.com> |
| In reply to | #39055 |
On Saturday, 31 October 2020 14:08:00 UTC+1, Julio Di Egidio wrote: > Here is a working version, for the fun of it: > <https://codepen.io/jp-diegidio/pen/mdExgZe> And here is more fun: Coin Flip Streaks--the game! <https://codepen.io/jp-diegidio/full/wvWjegE> The code is OK but nearing its limits: at the next iteration, from that View I'd extract a Model, and, if warranted, also a Controller. Anyway, for now, I've had enough of it. :) Enjoy and have a good week, Julio
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2020-11-01 23:44 -0800 |
| Message-ID | <fa6f3288-5a57-4346-a900-1122a8cafdabo@googlegroups.com> |
| In reply to | #39105 |
Den måndag 2 november 2020 kl. 06:57:52 UTC+1 skrev Julio Di Egidio: > On Saturday, 31 October 2020 14:08:00 UTC+1, Julio Di Egidio wrote: > > > Here is a working version, for the fun of it: > > <https://codepen.io/jp-diegidio/pen/mdExgZe> > > And here is more fun: > > Coin Flip Streaks--the game! > <https://codepen.io/jp-diegidio/full/wvWjegE> > > The code is OK but nearing its limits: at the next > iteration, from that View I'd extract a Model, and, > if warranted, also a Controller. > > Anyway, for now, I've had enough of it. :) > > Enjoy and have a good week, > > Julio LoL i don't think we solve the same problem.
[toc] | [prev] | [next] | [standalone]
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Date | 2020-10-31 18:24 +0100 |
| Subject | Re: boolean while loops "how to stop" and "make room for textout to textarea" |
| Message-ID | <i05kv9F6nc1U2@mid.individual.net> |
| In reply to | #39053 |
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.
The you did something wrong. But as usual you will comment yourself at
least 5-10 times here and present your findings.
> 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?
See above.
--
Arno Welzel
https://arnowelzel.de
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2020-10-31 10:44 -0700 |
| Subject | Re: boolean while loops "how to stop" and "make room for textout to textarea" |
| Message-ID | <c803369b-8162-4ea3-811f-c3f4778ba4aeo@googlegroups.com> |
| In reply to | #39061 |
Den lördag 31 oktober 2020 kl. 18:25:07 UTC+1 skrev Arno Welzel:
> 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.
>
> The you did something wrong. But as usual you will comment yourself at
> least 5-10 times here and present your findings.
>
> > 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?
>
> See above.
>
>
> --
> Arno Welzel
> https://arnowelzel.de
Have no idea what you talk about answer why javascript do not stop loop when condition get false "boolean", and why it do not ***manage*** to print out to form while in loop, much more interesting question.
Heck not even Basic had problem with that, honestly i do not think any programming language other then Javascript have this issues.
[toc] | [prev] | [next] | [standalone]
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Date | 2020-10-31 18:52 +0100 |
| Subject | Re: boolean while loops "how to stop" and "make room for textout to textarea" |
| Message-ID | <i05mjrF72lpU1@mid.individual.net> |
| In reply to | #39063 |
Jonas Thörnvall: [...] > Have no idea what you talk about answer why javascript do not stop > loop when condition get false "boolean", and why it do not > ***manage*** to print out to form while in loop, much more > interesting question. JavaScript *is* able to do this. However you try to run a endless loop in a *browser* and wonder why the browser does not handle input as long as the loop runs. You just don't understand what "event driven" programming means. If you want to create an application with user interaction you MUST NOT create while()-loops which don't stop as long as the user does something. Such loops MUST be in a separate thread otherwise there is no chance for the runtime to deal with user input. -- Arno Welzel https://arnowelzel.de
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2020-10-31 11:14 -0700 |
| Subject | Re: boolean while loops "how to stop" and "make room for textout to textarea" |
| Message-ID | <df4ee5e0-173e-40d1-867e-35bfb991f549o@googlegroups.com> |
| In reply to | #39065 |
Den lördag 31 oktober 2020 kl. 18:53:09 UTC+1 skrev Arno Welzel: > Jonas Thörnvall: > > [...] > > Have no idea what you talk about answer why javascript do not stop > > loop when condition get false "boolean", and why it do not > > ***manage*** to print out to form while in loop, much more > > interesting question. > > JavaScript *is* able to do this. However you try to run a endless loop > in a *browser* and wonder why the browser does not handle input as long > as the loop runs. You just don't understand what "event driven" > programming means. You are funny the event we talk about is pushing the button and it work perfectly, what does not work is javascript handling it, apparently it is occupied within a loop. So maybe it is just a case of javascript being single threaded. > > If you want to create an application with user interaction you MUST NOT > create while()-loops which don't stop as long as the user does > something. Such loops MUST be in a separate thread otherwise there is no > chance for the runtime to deal with user input. That is basicly what i want to know, why aren't boolean while loops run in separate threads? > > -- > Arno Welzel > https://arnowelzel.de
[toc] | [prev] | [next] | [standalone]
| From | John G Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2020-11-01 11:45 +0000 |
| Subject | Re: boolean while loops "how to stop" and "make room for textout to textarea" |
| Message-ID | <3r7tpfhth4n7toe3figrnvl9jr3ottf580@4ax.com> |
| In reply to | #39067 |
On Sat, 31 Oct 2020 11:14:46 -0700 (PDT), Jonas Thörnvall <jonas.thornvall@gmail.com> wrote: <snip> >That is basicly what i want to know, why aren't boolean while loops run in separate threads? So you want the HTML standard to be updated to say that the document MUST be displayed by a multi-core processor running an operating system that allows applications to demand more than one core. Dream on! John
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.lang.javascript
csiph-web