课程: Java Essential Training: Syntax and Structure
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Nested loops
- [Instructor] Sometimes, your repetitive tasks also contain repetitive subtasks. In this case, you need a loop inside of a loop. These are known as nested loops. In this problem, we need to find the average test scores for each student in the class. We know there are 24 students in the class, and that there's four tests that have been given. We need to loop through all 24 of the students, and since we know how many times we need to iterate, we can use a for loop. So we'll say, let's process all students, and we'll do so with this for loop where we initialize i to zero. We'll say i is less than the number of students. So keep going while i is less than the number of students, and then increment i by one each time the loop is run. Each iteration of the loop will focus on one student. Now that we have an individual student inside of this loop, we need to look at all four of their tests, which means we're going to need another…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。