Bạn thường sẽ có các chương trình chấm dứt và hiển thị một thông báo lỗi, chẳng hạn như ngoại lệ trong Một số lượng đáng kinh ngạc của sinh viên chỉ cần cung cấp tại thời điểm đó, nói rằng "nó không làm việc", hay "chương trình của tôi đã chết", mà không bao giờ đọc các thông báo lỗi | Java Concepts 5th Edition Quality Tip Use for Loops for Their Intended Purpose A for loop is an idiom for a while loop of a particular form. A counter runs from the start to the end with a constant increment for set counter to start test whether counter at end update counter by increment . . . counter start end increment not changed here If your loop doesn t match this pattern don t use the for construction. The compiler won t prevent you from writing idiotic for loops Bad style-unrelated header expressions for Inputs x 0 sum sum x count for int i 1 i years i Bad style-modifies counter if balance targetBalance i years 1 else double interest balance rate 100 balance balance interest These loops will work but they are plainly bad style. Use a while loop for iterations that do not fit the for pattern. 247 Chapter 6 Iteration Page 19 of 82 Java Concepts 5th Edition 242 Common Error Forgetting a Semicolon Occasionally all the work of a loop is already done in the loop header. Suppose you ignored Quality Tip then you could write an investment doubling loop as follows for years 1 balance balance balance rate 100 targetBalance years years The body of the for loop is completely empty containing just one empty statement terminated by a semicolon. If you do run into a loop without a body it is important that you make sure the semicolon is not forgotten. If the semicolon is accidentally omitted then the next line becomes part of the loop statement for years 1 balance balance balance rate 100 targetBalance years years You can avoid this error by using an empty block instead of an empty statement. Common Error A Semicolon Too Many What does the following loop print sum 0 for i 1 i 10 i sum sum i sum Of course this loop is supposed to compute 1 2 . 10 55. But actually the print statement prints 11 Chapter 6 Iteration Page 20 of 82 Java Concepts 5th Edition Why 11 Have another