Nested while loops for populating lists


Author
Message
Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 13K, Visits: 104K

You need to set c2 back to 0 before you enter the 2nd while loop. (Or after exiting it, doesn't matter in this case. Use whatever is clearer to you.)


Before entering:

// aim of the script to generate 16 trials that show the following sequences of numbers
// 1 1
// 1 2
// 2 1
// 2 2

// attempting to do this by programmatically populating lists


// stmulus 1
<text thetext>
/items=("1","2")
/select =list.anumber.nextvalue
/ position = (45%, 50%)
</text>
// stimulus 2
<text thetext2>
/items=("1","2")
/select =list.anumber2.nextvalue
/ position = (55%, 50%)
</text>
//list to populate desired end state (1,1,2,2)
<list anumber>
/items=()
/selectionrate = always
/select = sequence
</list>
//list to populate desired end state (1,2,1,2)
<list anumber2>
/items=()
/selectionrate = always
/select = sequence
</list>

//loop through 2 states of c
//calculate the target variable for writing to the list w
// update the control variable to terminate the loop when required c
//loop through 2 states of c2 (at each level of the prior loop c)
//calculate the target variable for writing to the list w2
// update the control variable to terminate the loop when required c2
// write the values when the final value is calculated w and w2

<expt e>
/ onexptbegin = [
    var c =0;
    var w =0;
    var c2 =0;
    var w2 =0;
    
    while (c<2) {
        w = c+1;
        c +=1;
        c2 = 0;
        while (c2<2) {
            w2 = c2+1;
            c2 +=1;
            list.anumber.appenditem(w);
            list.anumber2.appenditem(w2);
        }
    };
]
/ blocks = [1=b]
</expt>

<block b>
/trials=[1-4 =t]
</block>

<trial t>
/ posttrialpause = 100
/ pretrialpause = 100
/stimulustimes = [0=thetext, thetext2]
/ inputdevice = keyboard
/ validresponse = (" ")
</trial>


After exiting:

// aim of the script to generate 16 trials that show the following sequences of numbers
// 1 1
// 1 2
// 2 1
// 2 2

// attempting to do this by programmatically populating lists


// stmulus 1
<text thetext>
/items=("1","2")
/select =list.anumber.nextvalue
/ position = (45%, 50%)
</text>
// stimulus 2
<text thetext2>
/items=("1","2")
/select =list.anumber2.nextvalue
/ position = (55%, 50%)
</text>
//list to populate desired end state (1,1,2,2)
<list anumber>
/items=()
/selectionrate = always
/select = sequence
</list>
//list to populate desired end state (1,2,1,2)
<list anumber2>
/items=()
/selectionrate = always
/select = sequence
</list>

//loop through 2 states of c
//calculate the target variable for writing to the list w
// update the control variable to terminate the loop when required c
//loop through 2 states of c2 (at each level of the prior loop c)
//calculate the target variable for writing to the list w2
// update the control variable to terminate the loop when required c2
// write the values when the final value is calculated w and w2

<expt e>
/ onexptbegin = [
    var c =0;
    var w =0;
    var c2 =0;
    var w2 =0;
    
    while (c<2) {
        w = c+1;
        c +=1;
        //c2 = 0;
        while (c2<2) {
            w2 = c2+1;
            c2 +=1;
            list.anumber.appenditem(w);
            list.anumber2.appenditem(w2);
        }
        c2 = 0;
    };
]
/ blocks = [1=b]
</expt>

<block b>
/trials=[1-4 =t]
</block>

<trial t>
/ posttrialpause = 100
/ pretrialpause = 100
/stimulustimes = [0=thetext, thetext2]
/ inputdevice = keyboard
/ validresponse = (" ")
</trial>


Edited Last Year by Dave
kev_dent
kev_dent
Partner Member (820 reputation)Partner Member (820 reputation)Partner Member (820 reputation)Partner Member (820 reputation)Partner Member (820 reputation)Partner Member (820 reputation)Partner Member (820 reputation)Partner Member (820 reputation)Partner Member (820 reputation)
Group: Forum Members
Posts: 47, Visits: 153
Thanks Dave.
I see where I was going wrong now.
The loops were only executing once since I didn't reinitialise to zero.
I scaled up the example and it works well.
I forgot to reset to zero since I am used to using for loops, is there any implementation of for loops in inquisit?
Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 13K, Visits: 104K
kev_dent - 11/30/2023
Thanks Dave.
I see where I was going wrong now.
The loops were only executing once since I didn't reinitialise to zero.
I scaled up the example and it works well.
I forgot to reset to zero since I am used to using for loops, is there any implementation of for loops in inquisit?

No, Inquisit 6 only has while loops.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Reading This Topic

Explore
Messages
Mentions
Search