Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #23972
| From | Tim Streater <timstreater@greenbee.net> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Program logic weirdness? |
| Date | 2014-04-27 13:20 +0100 |
| Message-ID | <270420141320426439%timstreater@greenbee.net> (permalink) |
| References | (1 earlier) <75140a58-803e-4694-9b49-6d4561736bb8@googlegroups.com> <0.a3b4f471693338248a20.20140426123508BST.87y4ys5no3.fsf@bsb.me.uk> <f4a2b34c-d7b7-4974-a6f6-1582ce0045ff@googlegroups.com> <0.6fc64329016b6998cc1a.20140426223412BST.87a9b76ai3.fsf@bsb.me.uk> <2f7c3181-f823-4cbf-9f86-c3d43e96f5cf@googlegroups.com> |
In article <2f7c3181-f823-4cbf-9f86-c3d43e96f5cf@googlegroups.com>,
<jonas.thornvall@gmail.com> wrote:
> I think you are totally wrong Ben, we are basicly speaking about a
> print/write function, and if one should be able to steer what will be
> printout *before* one goes into the loop.
>
> Otherwise you will have to *fiddle* and doing unneccessary checks *within*
> loop.
>
> If you can not see this, you may still be a good programmer but i am sure any
> program language you developed would be *convoluted*.
>
> This is not even logic, its mostly common sense and i find it a bit weird
> that some people whose profession is programming totally lose it.
I haven't been following this from the beginning, so I am not quite
sure what is being asked for here. ISTM that you are talking about
printing inside a loop, with perhaps a condition attached to the
printing. Something like:
for (i=0; i<limit; i++)
{
if (cond) print ( ... );
}
Now you are saying that cond is perhaps complicated and you don't want
to be recomputing that each time around the loop.
I see two possibilities:
1) cond does not depend on the loop counter, i.
2) cond *does* depend on the loop counter, i.
In case (1) you simply optimise it by taking the if out of the loop and
doing:
if (cond)
{
for (i=0; i<limit; i++)
{
print ( ... );
}
}
In case (2) you *cannot* do that and you *must* leave the if as it is.
This is true whether or not cond is simple or complicated.
If you do not understand why this is so, then I suggest you need to
learn how computer processors work.
Or are you asking a different question altogether? If so then you have
not expressed it clearly.
--
"The idea that Bill Gates has appeared like a knight in shining armour to
lead all customers out of a mire of technological chaos neatly ignores
the fact that it was he who, by peddling second-rate technology, led them
into it in the first place." - Douglas Adams
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Program logic weirdness? jonas.thornvall@gmail.com - 2014-04-25 22:53 -0700
Re: Program logic weirdness? jonas.thornvall@gmail.com - 2014-04-25 22:57 -0700
Re: Program logic weirdness? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-04-26 12:35 +0100
Re: Program logic weirdness? jonas.thornvall@gmail.com - 2014-04-26 07:59 -0700
Re: Program logic weirdness? jonas.thornvall@gmail.com - 2014-04-26 08:11 -0700
Re: Program logic weirdness? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-04-26 22:34 +0100
Re: Program logic weirdness? jonas.thornvall@gmail.com - 2014-04-27 00:44 -0700
Re: Program logic weirdness? Tim Streater <timstreater@greenbee.net> - 2014-04-27 13:20 +0100
Re: Program logic weirdness? jonas.thornvall@gmail.com - 2014-04-27 06:09 -0700
Re: Program logic weirdness? Tim Streater <timstreater@greenbee.net> - 2014-04-27 18:30 +0100
Re: Program logic weirdness? jonas.thornvall@gmail.com - 2014-04-27 12:13 -0700
Re: Program logic weirdness? jonas.thornvall@gmail.com - 2014-04-28 02:33 -0700
Re: Program logic weirdness? jonas.thornvall@gmail.com - 2014-04-27 06:25 -0700
Re: Program logic weirdness? Denis McMahon <denismfmcmahon@gmail.com> - 2014-04-27 14:55 +0000
Re: Program logic weirdness? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-04-27 15:41 +0100
Re: Program logic weirdness? jonas.thornvall@gmail.com - 2014-04-27 13:57 -0700
Re: Program logic weirdness? jonas.thornvall@gmail.com - 2014-04-25 23:18 -0700
Re: Program logic weirdness? jonas.thornvall@gmail.com - 2014-04-25 23:23 -0700
Re: Program logic weirdness? Christoph Michael Becker <cmbecker69@arcor.de> - 2014-04-26 15:06 +0200
Re: Program logic weirdness? jonas.thornvall@gmail.com - 2014-04-26 08:00 -0700
Re: Program logic weirdness? jonas.thornvall@gmail.com - 2014-04-26 08:06 -0700
csiph-web