A. What Is A While Loop A While Loop Iterates Over A Code Block If A Given - 20241029 - 190047 - 0000
A. What Is A While Loop A While Loop Iterates Over A Code Block If A Given - 20241029 - 190047 - 0000
BSIS 104
Answer the following questions:
d. When to Use Each and Their Differences While Loop is good when you want to loop until a
condition is no longer true, like reading data from a file until you reach the end. It checks the
condition before each loop so it may not run at all if the condition is false to begin with.
Do...While Loop is good when you want the code to run at least once before checking the
condition. For example if you need to show a prompt for user input and then validate it, the
do...while loop will make sure the prompt is shown at least once. For Loop is used when you know
the exact number of iterations. For example it’s great for iterating over elements in an array or
doing something a specific number of times. It simplifies loops with a known range, as all parts of
the loop (initialization, condition and increment) are in one place.