In this episode, let's have a look at typical simple applications of the concepts presented until now related to "dynamic arrays" [a.k.a. "vectors"]. Let's assume, for example, that we have a dynamic array that contains "doubles", that we name "tab"; it is initialized at the beginning with 10 "doubles", all null. How can we print the elements of the vector? If you don't need to print the indexes, for instance to print "the element at position 0 is" or "the first element is", but only print the contents of the vector, you can use an iteration as introduced in C++ 2011. So, for example, begin by printing a message "Le tableau contient :" [TN: means "The vector contains:" ] then use a C++-11 loop with the columns (':') [TN: a.k.a. "for-range loop"] here, which separate on one side the vector that we want to iterate over, named "tab" and then, on the other side, choose a name of an element to iterate through this vector so we'll name it here "element". Here we have a loop that will stop at this point and that uses the variable name "element" to indicate the different elements of this vector "tab". As here iterating through the vector to print it doesn't modify the vector, we don't need to add the reference character between "auto" and the variable name. On the other hand, if you need to make the indexes explicit, it will be necessary somewhere to indicate this index and therefore have an additional variable. To achieve this, we'll declare a variable i. We'll use a for-loop like we have seen at the beginning, in the course about control statements, which will declare i of type size_t beginning at the index 0, the first element of the vector is at index 0, separate the for into the three parts with the semi-column (';') After the first part, we have the condition: here, it's "as long as i is strictly less than size"; actually we go to tab.size() minus 1 and, here, one by one. Therfore, this allows us in the loop, to print the index we are iterating over, the index of the elements we are iterating over. For example, it will print "l'élément 0 vaut" (= "the element 0 has the value") followed by the value of the first element stored in the vector, stored at the index 0. In these two examples in which we print the elements of the vector, we don't have to modify the elements of the vector. Now, let's see an example in which we want to, for example, affect the value, to all the elements of the vector, the value 1.2, for instance. If we want to use a C++-11 loop, we'll declare here "for(auto" with the symbol to indicate that we are going to modify, a variable name ('&') -- I had chosen "element" beforehand, here, I choose "el" -- the column (':') to separate the two parts, and then the name of the vector. In this loop, we'll therefore be able to use "el" as a variable name that will alternately iterate over the different elements of the vector "tab" and therefore, here, for each element, we put the value 1.2. We could also with a vector if we wanted to directly assign the whole vector, we could also use -- but this goes beyond the scope of illustrating for-loops -- we coud also use a global affectation of one vector to another. So here we are going to overwrite the vector, the old value of the vector, by the new value of a vector that is, so, we have a look here, element by element : a vector that contains doubles which we initialize, at the beginning, with a certain size which is the former size of the vector tab -- so we pass tab.size() -- all the elements of which have the value 1.2. It does indeed create a new vector that has exactly tab.size() elements and with every element having the value 1.2. It's the same as if you had declared using two lines: first a vector "tab2" which is a vector of doubles, initialized with the size of tab, that is, tab.size(), all with the value 1.2; and that you then had made a copy of "tab2" into "tab". We can write it like this, on a single line, in a compact way, by declaring here what is called an "anonymous vector". We haven't put any name here where we would have normally put the name "tab2" if we had declared it using two lines. It's a vector without a name, an anonymous vector. Such an expression, like this one, can perfectly be written, it's an existing vector that is promptly created before being copied into "tab". Another typical example of modification of the elements of a vector, is when we ask their values to the user. Again, we have two cases. Either we want to explicitly print the indexes, the indexes of the elements of the vector, or we simply want to ask them, the elements of the vector, one after the other, without making the indexes explicit. Let's have a look at these two cases. If we don't have to make the indexes explicit, then we can use a C++-11 for-loop [a.k.a. "range for-loop"]. But as we want to modify the vector, as we are going to input the values, we are here going to use a loop with references. We recognize the column (':') of the C++-11 loops, and the two parts, the vector "tab" that we want to modify and here the declarative part with the name we have chosen to iterate over the vector's elements, for example, "element". Then, in this loop -- I mean, in the body of this loop, indicated by this block here -- in this loop, we're going to print the message "Entrez l'élément suivant" [TN: means "enter the next element"], for example, and then input in the variable "element". The variable "element" will once again iterate over the different elements of the vector beginning with the first, then, when we'll do the second iteration, with the second element of the vector, then, when we'll re-loop in the third iteration, we'll have the third element of the vector, etc. until we arrive at the last element of the vector. If we want to make the indexes explicit, we'll use the standard for-loop separated into three parts with the semicolon (';'). Here we declare as usual an integer i of type size_t, at the index of the first element, that is the index zero. While i is strictly less than tab.size() we increment it, here, 1 by 1. Then here we print the index, -- as wanted, that's why we introduced i! -- so we write: "Entrez l'élement 0" (= "input the element 0"), the element 1, etc. Then, finally, we get from the keyboard the value of the element at the index i in the vector "tab" so "tab[i]", which indicates this element.