Learn creative coding writing simple programs

54. Infinite Forest? Combine random words using an Array

Arrays allow us to work with a collection of items of the same kind. For example, a list of numbers, or a list of words. In this episode we create two list of words and pick randomly one word from each list to create funny combinations. To declare an array we write square brackets behind the variable type. For example, instead of float we would write float[]. For String, we type String[]. An equal sign follows, and then a list of elements surrounded by curly braces and a semicolon ";" at the end of the line. Notice that when we use curly braces with if() or while() sentences, we don't write semicolons behind { or }. But we do on the line where we define an array.
Also note that inside an if statement you type TWO equal signs to compare. For example, if(a == 3) { ... It is a ver common mistake to type only one equal sign. In that case you don't get an error, but the program does not work as you expect.

Tags: random, word, text, array

Code editor

You can make changes to the code below. Then

Questions and comments

Try to stay close to the topic of this episode. Use the Processing forums for help with unrelated Processing projects (or hire me for help ;-)

To indicate that a word in your comment is code, use the `backtick`. Example
Do `float` and `int` smell similar?
To highlight code blocks, surround it with ``` code-fences ``` like this:
``` void setup() { size(600, 600); } ```