>
> ^ note: ^3 means the integer "just before" 3  (zero is presume to be the
> start point)
>
>           3^ means the integer "just after" 3  (an ending point is
> required)
>

No, it does not. Go back and read what Brad wrote; he was quite explicit.

Nothing about the range 0 ..^ 3 (for which "^3" is just a short-cut) says
anything about integers. It is the range of numbers (real numbers if you
like) ranging from 0 to 3, but excluding 3. In standard mathematical
notation that would be "[0,3)". If you iterate over the range then you
start with the beginning of the range and keep adding one until you reach
the end (in this case ignoring the final value if it is equal to the
end-point).

If the range were 0.5 .. 3 then the iterated values would be 0.5, 1.5 and
2.5.

On Fri, 1 Jan 2021 at 16:32, ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> On 12/30/20 5:39 PM, ToddAndMargo via perl6-users wrote:
> > Hi All,
> >
> > In the following for loop:
> >
> >      for ^$nCount -> $i {
> >
> > What is the ^ doing?
> >
> > Confused again,
> > -T
>
> With wonderful explanations for many others, my notes:
>
>
> ^ note: ^3 means the integer "just before" 3  (zero is presume to be the
> start point)
>
>           3^ means the integer "just after" 3  (an ending point is
> required)
>
>
> Looping using an integer (avoids having to use a C loop):
>
>     # loop to "just before" $x starting at 0 by 1
>     > my $x=3; for ^$x -> $i { print "i = $i\n"; }
>     i = 0
>     i = 1
>     i = 2
>
>     # loop from 3 to 5 by 1
>     > for 3..5 -> $i { print "i = $i\n"; }
>     i = 3
>     i = 4
>     i = 5
>
>     # loop from 3 to "just before" 6 by 1
>     > for 3..^6 -> $i { print "i = $i\n"; }
>     i = 3
>     i = 4
>     i = 5
>
>     # loop from "just after" 3 to 6 by 1
>     > for 3^..6 -> $i { print "i = $i\n"; }
>     i = 4
>     i = 5
>     i = 6
>
>     # loop from "just after" 3 to "just before" 7 by 1
>     > for 3^..^7 -> $i { print "i = $i\n"; }
>     i = 4
>     i = 5
>     i = 6
>
>
>

Reply via email to