Loops: How Do I Repeat Program Instructions Efficiently?
摘要
In programs we often need to repeat one or more similar instructions. To do this, we could simply write the instructions several times in a row. However, this is not only tedious and error-prone, but also always presents us with a problem if, at the time we write the program, it is not clear how many times the statements need to be executed in succession. This is where loops come into play. They allow controlled repetitions of the same (or almost the same) program code and make your programming work more efficient and your program look elegant.