Dale - Computer Science Illuminated 275

Dale - Computer Science Illuminated 275 - that C++ and Java...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
248 Chapter 8 High-Level Programming Languages The while loop is called a pretest loop. This means that the testing takes place before the loop is executed. If the condition is false initially, the loop is not entered. What happens if the incrementation statement is omitted? The Boolean expression never changes. If the expression was false to begin with, nothing happens; the loop is just not executed. If the expression is true to begin with, the expression never changes, so the loop executes forever. Actually, most computing systems have a timer, so the program would not actually run forever. The program would halt with an error message. A loop that never terminates is called an infinite loop . The following table shows the implementation of the algorithm in Ada, VB.NET, C++, and Java. Incrementing the content of a variable by one is such a common operation
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: that C++ and Java provide a shortcut. In these languages, count++ is a short cut for the statement count = count + 1 . Event-controlled loops Loops in which the number of repetitions is controlled by an event that occurs within the body of the loop itself are called event-controlled loops. To implement an event-controlled loop using a while statement, there are again three parts to the process. The event must be initialized, the event must be tested, and the event must be updated. Count-Controlled Loop with a while Statement Language Ada pD91 ) "i Tz 82 pD91 C) E 1 8DDS hhh pD91 ) pD91 F "i 29 8DDSi pD91 ) " wz 82 gPD91 C) 8 1B hhh PD91 ) PD91 F " *9 wz 82 PD91 ) "i Tz 82 gPD91 C) 8 1B { hhh PD91FFi } VB.NET C++/Java...
View Full Document

Ask a homework question - tutors are online