[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Numeric for loop with rationals
- From: Francisco Olarte <folarte@...>
- Date: Tue, 30 Jan 2018 16:45:08 +0100
On Tue, Jan 30, 2018 at 1:23 PM, Soni "They/Them" L. <fakedme@gmail.com> wrote:
> On 2018-01-30 06:58 AM, Francisco Olarte wrote:
...
>> C++ does not have numeric for, so it doesn't count either.
> for (int i = 0; i < 100; i++) { printf("%d\n", i); }
> Looks like it does, it's just more flexible than Lua's.
No, it does not. It's a generic loop, you are just using it to count,
which is one of the things it does.
K&R2 says "The for statement is a loop, a generalization of the
while.". T.C++P.L. says something on the line, but longer. It's a much
more powerful construct than a numeric loop, it can be used to build
numeric loops, list traversals, infinite loops.
Numeric for loops work with numbers, not with any condition, like lua
or fortran 66/77 do ( haven't use fortran in ages, so I'm not sure
about later variants ), or, IIRC, pascal.
A numeric loop does not need you to specify the type of the control
var, or that the end comparison is numeric.
If you count a generic loop used with numbers as a numeric loop, you
have to count a python range loop too, and even one implemented with
if & goto, but then you are talking about other thing, let's call it a
programming pattern or whatever, not about a language features.
Francisco Olarte.