A nested loop is used when a loop has to be programmed within another loop to perform a specific task. In a nested loop, the inner loop repeats for a number of times for each iteration of the outer loop. Nested loops are widely used in pattern printing.