It does not look like an array from 0 to ($nCount - 1). It only iterates
like that.

It is a Range object from 0 to $nCount excluding $nCount.

    ^9 === Range.new( 0, 9, :excludes-max ) # True
    0 ~~ ^9 # True
    1 ~~ ^9 # True
    0.5 ~~ ^9 # True
    8 ~~ ^9 # True
    8.99999 ~~ ^9 # True

    9 ~~ ^9 # False

In the case of `for ^9 {…}` it iterates starting at 0, and continuing to
just before 9.

It does that because `for` iterates the Range object.

It does NOT store any values other than the min, max and either excludes.

An array would store the values in the middle. Which would be a waste of
memory.
Which is why it does not do that.

On Wed, Dec 30, 2020 at 8:09 PM 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
>
> Used in context, the ^ makes the integer $nCount look
> like an array of 0 to ($nCount - 1).  Am I missing
> something?
>
> my $x=4;
> for ^$x -> $i { print "i = $i\n"; }
>
> i = 0
> i = 1
> i = 2
> i = 3
>
>

Reply via email to