正在加载图片...
The Repeat-N-Times Idiom One strategy for generalizing the addition program is to use the Repeat-N-Times idiom,which executes a set of statements a specified number of times.The general form of the idiom is for (int i=0;i<repetitions;i++){ statements to be repeated The information about the number of repetitions is specified by the first line in the pattern,which is called the header line. The statements to be repeated are called the body of the for statement and are indented with respect to the header line. A control statement that repeats a section of code is called a loop. Each execution of the body of a loop is called a cycleThe Repeat The Repeat-N-Times Idiom Times Idiom One strategy for generalizing the addition program is to use the Repeat-N-Times idiom, which executes a set of statements a specified number of times. The general form of the idiom is for (int i = 0; i < repetitions; i++) { statements to be repeated } As is true for all idiomatic patterns in this book, the italicized words indicate the parts of the pattern you need to change for each application. To use this pattern, for example, you need to replace repetitions with an expression giving the number of repetitions and include the statements to be repeated inside the curly braces. The information about the number of repetitions is specified by the first line in the pattern, which is called the header line. The statements to be repeated are called the body of the for statement and are indented with respect to the header line. A control statement that repeats a section of code is called a loop. Each execution of the body of a loop is called a cycle. for (int i = 0; i < repetitions; i++) { statements to be repeated }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有