Skip to main content Accessibility help
×
Hostname: page-component-848d4c4894-nmvwc Total loading time: 0 Render date: 2024-06-20T01:42:03.437Z Has data issue: false hasContentIssue false

Chapter VI - Loops and Arrays in E-Basic

Published online by Cambridge University Press:  22 November 2022

Get access

Summary

In this chapter, you will learn

The most important thing you will learn in this chapter is how to use loops and arrays in E-Basic. We will then show how you can apply this knowledge to make quasi-randomised Lists and program a working memory task. Unfortunately, creating quasi-randomised Lists is not that straightforward. You will need InLine scripts to put stimuli into your own list-wise variable structure called an Array, shuffle that Array, check it, determine if it is shuffled according your desired criteria, and finally, put your shuffled Array back into the List of the experiment. We will start by highlighting the various programming elements involved here – basically, Loops and Arrays– that are needed to fulfil this task.

Looping with Labels

So far, you have learned how to use variables, If-Then statements, and Labels. These are the fundamental elements of E-Basic, which allow you to implement almost any code you need. Imagine, for instance, that you want to present the numbers 1 to 10 in ten message boxes presented in a row. You now know that these lines of code should simply work:

However, imagine that you need 100 of these boxes. We would end up with a severe case of repetitive strain injury from writing out all this code. Fortunately, there is an easy solution. Given that we know how to use variables, the implementation below is much more flexible, and doesn't need that much code:

The code above implements a structure that is known as a loop. The simple loop in this example repeats the MsgBox line of code ten times, with the value in Counter increasing from 1 to 10 with each repetition. Note that the START_OF_LOOP line (with the colon!) marks a particular location in the script with a Label. This is the textual equivalent of the Label object that can be dragged into your experimental timeline (as explained in Chapter III).

The flow chart on the next page shows the corresponding function. Note that the arrow pointing upwards loops back to the previous location in the code marked by the Label.

With this example, we’ve still got eight lines of code. Surely we can do better than that! Well, it turns out that the smart guys who originally developed BASIC added some extra looping structures that need even fewer lines of code.

Type
Chapter
Information
The E-Primer
An Introduction to Creating Psychological Experiments in E-Prime
, pp. 161 - 184
Publisher: Amsterdam University Press
Print publication year: 2019

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Save book to Kindle

To save this book to your Kindle, first ensure coreplatform@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

Available formats
×

Save book to Dropbox

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.

Available formats
×

Save book to Google Drive

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.

Available formats
×