other control statements. Indentation only creates blocks and sub-blocks like how we create blocks within a set of { } in languages like C, C++ etc. Note Here is another program which illustrates the use of range() to find the sum of numbers to 12th Computer Chapter - - Control Structures n = sum = for counter in range( ,n+ ): sum = sum + counter print("Sum of until %d: %d" % (n,sum)) Output: Sum of until : In the above code, n is initialized to , sum is initialized to , the for loop starts executing from , for every iteration the value of sum is added with the value of counter variable and stored in sum. Note that the for loop will iterate from till the upper limit - (ie.
Value of n is set as , so this loop will iterate for values from to only, that is the reason why we have set the upper limit as n+ ) Example . : # program to calculate the sum of numbers to for loop can also take values from string, list, dictionary etc. which will be dealt in the later chapters. Note Following is an example to illustrate the use of string in range() for word in 'Computer': print (word,end=' ') else: print ("\nEnd of the loop") Output C o m p u t e r End of the loop Example .
: program to illustrate the use of string in range() of for loop (iii) Nested loop structure A loop placed within another loop is called as nested loop structure. One can place a while within another while; for within another for; for within while and while within for to construct such nested loops. Following is an example to illustrate the use of for loop to print the following pattern 12th Computer Chapter - - i= while (i<= ): for j in range ( ,i): print (j,end='\t') print