1. Introduction Earlier we examined the for loop, which executes a set of statements a definite number of times specified by the programmer. In many situations, however, the number of iterations in a loop is unpredictable. The loop eventually completes its work, but only when a condition changes. For example, the user might be asked for a set of input values. In that case, only the user knows the number she will enter. The program’s input loop accepts these values until the user enters a special value or sentinel that terminates the input. This type of process is called conditional iteration. In this section, we explore the use of the while loop to describe conditional iteration.
2. The Structure and Behavior of a while Loop Conditional iteration requires that a condition be tested within the loop to determine whether the loop should continue. Such a condition is called the loop’s continuation condition. If the continuation condition is false, the loop ends. If the continuation condition is true, the statements within the loop are executed again. The while loop is tailor-made for this type of control logic.
المادة المعروضة اعلاه هي مدخل الى المحاضرة المرفوعة بواسطة استاذ(ة) المادة . وقد تبدو لك غير متكاملة . حيث يضع استاذ المادة في بعض الاحيان فقط الجزء الاول من المحاضرة من اجل الاطلاع على ما ستقوم بتحميله لاحقا . في نظام التعليم الالكتروني نوفر هذه الخدمة لكي نبقيك على اطلاع حول محتوى الملف الذي ستقوم بتحميله .
|