Count-Controlled Loops
– used for iterating steps a specific number of times. It is used when the number of iterations to take place is already known. It uses a counter to keep track of how many times the set of commands has been repeated. Count-controlled loops are executed using FOR statements. 1. for– specifies the starting point of the iteration 2. range– indicates h
Count Controlled Loop Example
The above program works as follows: 1. The variable ‘count’ is used to keep track how may times the iteration happened. 2. The ‘for’ statement is used to determine where the loop starts. 3. The ‘range’ declaration signifies the number of instances the loop is to occur. 4. The variable ‘count’ regulates the repetition. 5. In every repetition, progra
Condition-Controlled Loops
– used for iterating steps continuously until a condition is met. It is used when the number of iterations to take place is unknown. The algorithm tests the condition to see if it is true. If true, the algorithm executes a command. If false, the algorithm goes back to step 1 and will continue to go back until the condition becomes true. Condition-c
Condition Controlled Loop Example
The above program works as follows: 1. The ‘while’ statement is used to indicate where the iteration starts. 2. The condition ‘answer = “yes”’ is used to manage the iteration. It must be set to “yes” at the start so the code runs at least once. 3. The program assesses the condition by checking if the variable ‘answer’ equals “yes”. 4. If the condit