Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #38085

Re: Logical conundrums if () else if()

From Soviet_Mario <SovietMario@CCCP.MIR>
Newsgroups comp.lang.javascript
Subject Re: Logical conundrums if () else if()
Date 2020-01-18 21:06 +0100
Organization A noiseless patient Spider
Message-ID <qvvogi$af3$1@dont-email.me> (permalink)
References <cd84bfc2-63ac-4a4f-bd76-9b144035b9ba@googlegroups.com>

Show all headers | View raw


On 28/12/19 09:40, Jonas Thörnvall wrote:
> How can two if statements that work perfectly standalone as single statments.
> Make outcome that differs when you put in, an else if statement to only execute one of them. The below statements have the statement with heavier conditioning first so not the second statement gets executed. Because both satisfy the noneboolean condition.
> 
> I probably done some very no no thingy.
> 
>   	
> 
> if (EDITEND<SELEND && document.getElementById("lockedit").checked){
>    SELLENGTH=SELEND-SELSTART;
>    document.getElementById("SB").value=EDITSTART+SELLENGTH;
>    document.getElementById("EB").value=SELEND;
> } else if (EDITEND<SELEND){ document.getElementById("EB").value=SELEND;}
> 

do you have the rock solid warranty that none of the 
statements/function calls MODIFIES the internal status of 
the objects probed ?
If somewhere sth gets changed by the inquiry, the order 
could become relevant.

a trivial example of what I mean

int q, k = 0;
if (k == 0) q = 0; else if (++ k != 0) q = 1;
if (++ k != 0) q = 0; else if (k == 0) q = 1;

the state of q depends on the order the two tests on k are 
executed.

maybe getElementById alters sth ... dunno ...


-- 
1) Resistere, resistere, resistere.
2) Se tutti pagano le tasse, le tasse le pagano tutti
Soviet_Mario - (aka Gatto_Vizzato)

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Logical conundrums if () else if() Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-12-28 00:40 -0800
  Re: Logical conundrums if () else if() "R.Wieser" <address@not.available> - 2019-12-28 12:21 +0100
    Re: Logical conundrums if () else if() Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-12-28 05:32 -0800
      Re: Logical conundrums if () else if() "R.Wieser" <address@not.available> - 2019-12-28 19:10 +0100
        Re: Logical conundrums if () else if() Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-12-28 12:16 -0800
          Re: Logical conundrums if () else if() "R.Wieser" <address@not.available> - 2019-12-29 08:52 +0100
          Re: Logical conundrums if () else if() Arno Welzel <usenet@arnowelzel.de> - 2019-12-30 21:35 +0100
            Re: Logical conundrums if () else if() Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-12-30 12:42 -0800
  Re: Logical conundrums if () else if() "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2019-12-28 09:37 -0800
    Re: Logical conundrums if () else if() Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2019-12-29 11:43 +0100
      Re: Logical conundrums if () else if() "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2019-12-29 08:14 -0800
  Re: Logical conundrums if () else if() Soviet_Mario <SovietMario@CCCP.MIR> - 2020-01-18 21:06 +0100
    Re: Logical conundrums if () else if() Soviet_Mario <SovietMario@CCCP.MIR> - 2020-01-19 01:22 +0100

csiph-web