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
Below you can ask and answer questions related to this video. If your question is unrelated to the video, please post it at the Processing Forum as I'm unable to help with all of your programs and still have enough free time to eat and sleep :)
comments powered by Disqus