text: Unit 15 – Array
  
  The code of the last example is very long. But actually almost the same things are repeated all the time, no? We can do it easier – using the array.
  
  An array is a special type of variable. It can not only store one but multiple values.
  
  Think of it as a cargo ship. It can store containers. Every container has got it’s own number. If you want to look inside, you need to tell the number. Those numbers start with 0 not with 1 what sometimes is confusing.
  
  Of course the array also has to be declared (created). There are several ways to do that.
  
  This is how to declare an empty array without value assignment.
  
  `int nums[6];`
  
  An array named «nums» is created. The variable type is int (integer numbers). Arrays usually can only store values of the same type. The 6 in the brackets means that our cargo ship has got six containers where we can put cargo (numbers) in. It is called the length of an array.
  
  An other way to create an array:
  
  `int nums[] = {10, 78, 45, 67, 38, 14};`
  
  Now we declare the array and directly assign values. We don’t have to tell it the length. By the way, you find the square brackets [] on your keyboard pressing Alt-Gr + 8 and Alt-Gr + 9 on a PC or Alt + 5 and Alt + 6 on a Mac. So, what is the length of the array? Right: It again is six.
  
  But how can we write values into the array? Actually, it is done the same way like with normal variables. The only difference is that we have to state the number of the container.
  
  `nums[3] = 50;`
  
  And how can we read it out? Let’s say we want to know the value of the fourth position (remember, it starts with 0 so the fourth position is 3) and write it into an other variable.
  
  `a = nums[3];`
  
  In the last unit, we played different tones. We had to repeat almost the same commands again and again. Now, we can simply put the frequencies into an array:
  
  `int frequencies[] = {262, 294, 330, 349, 392, 392);`
  
  Easy! We have an array of the variable type int. It is named frequencies and the frequencies we need are already assigned. OK, let’s see what is where:
  
  ``` frequencies[0] returns 262
  frequencies[1] returns 294
  frequencies[5] returns 392```
  
  Cool, we can use the array like a normal variable. We only have to state the position.
  For a melody we even need the duration of the tone. Let’s put it into a second array:
  
  `int tonDuration[]= {200, 200, 200, 200, 400, 400);`
  
  The length of both arrays must be the same. To play one by one we will use a for-loop. The counter variable will count, which tone should be played and sends it to the arrays:
  
  ```int frequencies[] = {262, 294, 330, 349, 392, 392};
  int tonDuration[]= {200, 200, 200, 200, 400, 400};
  int toneQuantity = 6;
  
  void setup() {
  
  }
  
  void loop() {
  for (int theTone=0; theTone< toneQuantity; theTone = theTone +1){
  tone(9, frequencies[theTone]);
  delay(tonDuration[theTone]);
  noTone(9);
  delay(tonDuration[theTone]);
  }
  }```
  
  This code is much shorter. Now, play the whole melody of the last unit.
  
  ```int frequencies[] = {262, 294, 330, 349, 392, 392, 440, 440, 440, 440, 392, 440, 440, 440, 440, 392, 349, 349, 349, 349, 330, 330, 392, 392, 392, 392, 262};
  int tonDuration[]= {200, 200, 200, 200, 400, 400, 200, 200, 200, 200, 800, 200, 200, 200, 200, 800, 200, 200, 200, 200, 400, 400, 200, 200, 200, 200, 800};
  int toneQuantity = 27;
  
  void setup() {
  
  }
  
  void loop() {
  for (int theTone=0; theTone< toneQuantity; theTone=theTone+1){
  tone(9, frequencies[theTone]);
  delay(tonDuration[theTone]);
  noTone(9);
  delay(tonDuration[theTone]);
  }
  }```
  
  Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.
explanation: The provided text is a detailed explanation of arrays in programming, specifically in the context of storing and accessing multiple values. It includes examples of declaring and using arrays, as well as a practical application of arrays to play a melody using a for-loop. The text does not contain any explicit math questions or answers.
distilabel_metadata.content: Evaluate the user given text extract and determine if it contains a math question and optionally and answer to this question.
  
  Output rules:
  
  1. Briefly describe the document and mention if it contains a question or a question and answer.
  2. Finalize the output with: Label: no-question,question,question-and-answer,multiple-question,multiple-question-and-answer
distilabel_metadata.role: system
distilabel_metadata.content: Unit 15 – Array
  
  The code of the last example is very long. But actually almost the same things are repeated all the time, no? We can do it easier – using the array.
  
  An array is a special type of variable. It can not only store one but multiple values.
  
  Think of it as a cargo ship. It can store containers. Every container has got it’s own number. If you want to look inside, you need to tell the number. Those numbers start with 0 not with 1 what sometimes is confusing.
  
  Of course the array also has to be declared (created). There are several ways to do that.
  
  This is how to declare an empty array without value assignment.
  
  `int nums[6];`
  
  An array named «nums» is created. The variable type is int (integer numbers). Arrays usually can only store values of the same type. The 6 in the brackets means that our cargo ship has got six containers where we can put cargo (numbers) in. It is called the length of an array.
  
  An other way to create an array:
  
  `int nums[] = {10, 78, 45, 67, 38, 14};`
  
  Now we declare the array and directly assign values. We don’t have to tell it the length. By the way, you find the square brackets [] on your keyboard pressing Alt-Gr + 8 and Alt-Gr + 9 on a PC or Alt + 5 and Alt + 6 on a Mac. So, what is the length of the array? Right: It again is six.
  
  But how can we write values into the array? Actually, it is done the same way like with normal variables. The only difference is that we have to state the number of the container.
  
  `nums[3] = 50;`
  
  And how can we read it out? Let’s say we want to know the value of the fourth position (remember, it starts with 0 so the fourth position is 3) and write it into an other variable.
  
  `a = nums[3];`
  
  In the last unit, we played different tones. We had to repeat almost the same commands again and again. Now, we can simply put the frequencies into an array:
  
  `int frequencies[] = {262, 294, 330, 349, 392, 392);`
  
  Easy! We have an array of the variable type int. It is named frequencies and the frequencies we need are already assigned. OK, let’s see what is where:
  
  ``` frequencies[0] returns 262
  frequencies[1] returns 294
  frequencies[5] returns 392```
  
  Cool, we can use the array like a normal variable. We only have to state the position.
  For a melody we even need the duration of the tone. Let’s put it into a second array:
  
  `int tonDuration[]= {200, 200, 200, 200, 400, 400);`
  
  The length of both arrays must be the same. To play one by one we will use a for-loop. The counter variable will count, which tone should be played and sends it to the arrays:
  
  ```int frequencies[] = {262, 294, 330, 349, 392, 392};
  int tonDuration[]= {200, 200, 200, 200, 400, 400};
  int toneQuantity = 6;
  
  void setup() {
  
  }
  
  void loop() {
  for (int theTone=0; theTone< toneQuantity; theTone = theTone +1){
  tone(9, frequencies[theTone]);
  delay(tonDuration[theTone]);
  noTone(9);
  delay(tonDuration[theTone]);
  }
  }```
  
  This code is much shorter. Now, play the whole melody of the last unit.
  
  ```int frequencies[] = {262, 294, 330, 349, 392, 392, 440, 440, 440, 440, 392, 440, 440, 440, 440, 392, 349, 349, 349, 349, 330, 330, 392, 392, 392, 392, 262};
  int tonDuration[]= {200, 200, 200, 200, 400, 400, 200, 200, 200, 200, 800, 200, 200, 200, 200, 800, 200, 200, 200, 200, 400, 400, 200, 200, 200, 200, 800};
  int toneQuantity = 27;
  
  void setup() {
  
  }
  
  void loop() {
  for (int theTone=0; theTone< toneQuantity; theTone=theTone+1){
  tone(9, frequencies[theTone]);
  delay(tonDuration[theTone]);
  noTone(9);
  delay(tonDuration[theTone]);
  }
  }```
  
  Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.
distilabel_metadata.role: user
distilabel_metadata.raw_output_q_a_detector_0: The provided text is a detailed explanation of arrays in programming, specifically in the context of storing and accessing multiple values. It includes examples of declaring and using arrays, as well as a practical application of arrays to play a melody using a for-loop. The text does not contain any explicit math questions or answers.
  
  Label: no-question