iterating over list with for loop having introduced listswe are ready to look at the second type of loop we will use in this bookthe for loop the for loop is less general than the while loopbut it is also bit simpler to use the for loop simply iterates over elements in listand performs operations on each onefor element in listthe key line is the first onewhich will simply run through the listelement by element for each pass of the loopthe single element is stored in the variable elementand the block of code inside the for loop typically involves calculations using this element variable when the code lines in this block are completedthe loop moves on to the next element in the listand continues in this manner until there are no more elements in the list it is easy to see why this loop is simpler than the while loopsince no condition is needed to stop the loop and there is no need to update variable inside the loop the for loop will simply iterate over all the elements in predefined listand stop when there are no more elements on the other handthe for loop is slightly less flexiblesince the list needs to predefined the for loop is the best choice in most cases in which we know in advance how many times we want to perform set of operations in cases in which this number is not knownthe while loop is usually the best choice for concrete for loop examplewe return to the investment growth example introduced above to write for loop for given tasktwo key questions must be answered(iwhat should the list containand (iiwhat operations should be performed on the elements in the listin the present casethe natural answers are (ithe list should be range of -values from zero to in steps of and (iithe operations to be repeated are the computation of and the printing of the two valuesessentially the same as in the while loop the full program using for loop thus becomes years [ for in yearsa ( + / )** print(naas with the while loopthe statements inside the loop must be indented simply by counting the lines of code in the two programs shows that the for loop is somewhat simpler and quicker to write than the while loop most people will argue that the overall structure of the program is also simpler and less error-pronewith no need to check criterion to stop the loop or to