Book contents
- Frontmatter
- Table of Contents
- Preface to the Second Edition
- Preface to the First Edition
- Introduction
- Chapter I E-Prime at a glance
- Chapter II List Attributes and Slides
- Chapter III Sound, movies, hardware, and nested Lists
- Chapter IV Beginning programming in E-Prime
- Chapter V Decision making in E-Basic
- Chapter VI Loops and Arrays in E-Basic
- Chapter VII Interactions between Slide objects and the Mouse
- Chapter VIII Various Input/Output devices
- References
- Appendix: Overview of available E-Objects
- About the authors
- Index
Chapter VI - Loops and Arrays in E-Basic
Published online by Cambridge University Press: 22 November 2022
- Frontmatter
- Table of Contents
- Preface to the Second Edition
- Preface to the First Edition
- Introduction
- Chapter I E-Prime at a glance
- Chapter II List Attributes and Slides
- Chapter III Sound, movies, hardware, and nested Lists
- Chapter IV Beginning programming in E-Prime
- Chapter V Decision making in E-Basic
- Chapter VI Loops and Arrays in E-Basic
- Chapter VII Interactions between Slide objects and the Mouse
- Chapter VIII Various Input/Output devices
- References
- Appendix: Overview of available E-Objects
- About the authors
- Index
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-PrimerAn Introduction to Creating Psychological Experiments in E-Prime, pp. 161 - 184Publisher: Amsterdam University PressPrint publication year: 2019