Definite Loops: A definite loop is a type of program loop where the number of iterations is predetermined before the loop begins execution. An example of a definite loop is the while loop:
sum = 0
current = 1n = int(input('Enter value: '))while current <= n:sum += currentcurrent += 1
In this case, although the value of n isn't known until the input is provided, its value is determined before the while loop starts executing. The loop will run "n times."
Indefinite Loops:
Infinite loop is an iterative control structure that never terminates (or eventually terminates with a system error). Infinite loops are generally the result of programming errors. For example, if the condition of a while loop can never be false, an infinite loop will result when executed.
Consider if the program segment omitted the statement incrementing variable current. Since current is initialized to 1, it would remain 1 in all iterations, causing the expression current <= n to always be true. Thus, the loop would never terminate.
current = 1n = int(input('Enter value: '))while current <= n:sum += currentcurrent = 1
Such infinite loops can cause a program to “hang,” that is, to be unresponsive to the user. In such cases, the program must be terminated by use of some special keyboard input (such as ctrl-C) to interrupt the execution.
Both definite and indefinite loops can be created using while statements.