课程: Java Essential Training: Syntax and Structure

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

For loop

For loop

- [Instructor] The for loop differs from other loops in that it's count controlled as opposed to condition controlled. Count control means the for loop executes a specified number of times. In this problem, we will write a program for a cashier that will scan a given number of items and tally the cost. On line 18, we've stored the number of items the cashier would like to scan and on line 20, we've initialized the total price as zero. Now we can create a for loop that will accumulate the price of each item. We start the for loop by writing the word for and a set of parentheses. Within the parentheses of a for loop exists three statements. The very first statement initializes a variable that we'll use to count the number of times the loop has been executed so far. We end this statement with a semicolon. I is a common variable name for an incrementer within the for loop. Also, when we're using loops in programming, it…

内容