106 Control Structures: Part 1 Chapter 4 product (Web hosting company)
Saturday, April 21st, 2007106 Control Structures: Part 1 Chapter 4 product <= 1000 product = 2 * product true false Fig. 4.5 Flowcharting the while repetition structure. Testing and Debugging Tip 4.2 Visual Studio .NET will not color a keyword properly unless that keyword is spelled correctly and with the correct case. Imagine, again, a deep bin of empty while structures that may be stacked and nested with other control structures to form a structured implementation of an algorithm s flow of control. The empty rectangles and diamonds are filled with appropriate actions and decisions. The flowchart clearly shows the repetition. The flowline emerging from the rectangle indicates that program control continues with the decision, which is tested during each iteration of the loop until the decision eventually becomes false. At this point, the while structure terminates, and control passes to the next statement following the while structure in the program. When the while structure begins executing, product is 2. Variable product is repeatedly multiplied by 2, taking on the values 4, 8, 16, 32, 64, 128, 256, 512 and 1024, successively. When product becomes 1024, the condition product <= 1000 in the while structure becomes false. This terminates the repetition with 1024 as product s final value. Execution continues with the next statement after the while. [Note: If a while structure s condition is initially false, the body statement(s) will never be executed.] 4.8 Formulating Algorithms: Case Study 1 (Counter-ControlledRepetition) To illustrate how algorithms are developed, we solve several variations of a class-averaging problem. Consider the following problem statement: A class of ten students took a quiz. The grades (integers in the range 0 to 100) for this quiz are available to you. Determine the class average on the quiz. The class average is equal to the sum of the grades divided by the number of students. The algorithm for solving this problem on a computer must input each of the grades, perform the averaging calculation and display the result. Let us use pseudocode to list the actions to execute and to specify the order of execution. We use counter-controlled repetition to input the grades one at a time. This technique uses a variable called a counter to control the number of times a set of statements will execute. In this example, repetition terminates when the counter exceeds 10. This section presents a pseudocode algorithm (Fig. 4.6) and the corresponding program (Fig. 4.7). In
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision mysql5 web hosting services