Solution Review: for Loops
In this review, we provide a detailed analysis of the solution to this problem.
We'll cover the following...
We'll cover the following...
Solution #1: Using for Loop
Explanation
We have a vector testVariable that contains all the numbers.
We initiate a for loop for all the elements in the vector (line number 2) and check whether that element is a multiple of , or both.
Solution #2: Using while Loop
Explanation
Here, we are using a while loop to solve this problem.
Remember we could fetch an element in a vector using square brackets
[].
We have fetched all elements of the vector using their indexes, for example, testVariable[1], testVariable[2]…testVariable[n]. Here, n is the last element (placed at length(testVariable)).
We iterate over all these indexes starting from to using the while loop.
There is another method to make loops using repeat.