O'Reilly logo

Quality Code: Software Testing Principles, Practices, and Patterns by Stephen Vance

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Encapsulate Loop Conditions

Sometimes the termination condition of a loop is independent of the data being manipulated in the loop. One example occurs when you are looking for an external trigger such as an event, signal, or sensor reading to stop. Imagine you were writing the preheat controller for a commercial oven. Simplified pseudo-code for the initial heating cycle might look something like Listing 8-3.

Listing 8-3: Simple pseudo-code for externally triggered loop termination

while(underSetTemperature()) {  keepHeating();}

We have changed the problem domain slightly, but this example closely resembles the example from the previous section. The underSetTemperature() method encapsulates the logic around continuing ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required