Loop Unrolling Last Updated : 11 Sep, 2023 Comments Improve Suggest changes Like Article Like Report Loop unrolling is a loop transformation technique that helps to optimize the execution time of a program. We basically remove or reduce iterations. Loop unrolling increases the program’s speed by eliminating loop control instruction and loop test instructions. Program 1: CPP // This program does not uses loop unrolling. #include<stdio.h> int main(void) { for (int i=0; i<5; i++) printf("Hello\n"); //print hello 5 times return 0; } Program 2: CPP // This program uses loop unrolling. #include<stdio.h> int main(void) { // unrolled the for loop in program 1 printf("Hello\n"); printf("Hello\n"); printf("Hello\n"); printf("Hello\n"); printf("Hello\n"); return 0; } Output: Hello Hello Hello Hello Hello Illustration: Program 2 is more efficient than program 1 because in program 1 there is a need to check the value of i and increment the value of i every time round the loop. So small loops like this or loops where there is fixed number of iterations are involved can be unrolled completely to reduce the loop overhead. Advantages: Increases program efficiency. Reduces loop overhead. If statements in loop are not dependent on each other, they can be executed in parallel. Disadvantages: Increased program code size, which can be undesirable. Possible increased usage of register in a single iteration to store temporary variables which may reduce performance. Apart from very small and simple codes, unrolled loops that contain branches are even slower than recursions. Reference: https://en.wikipedia.org/wiki/Loop_unrolling Comment More infoAdvertise with us Next Article Loop Unrolling H Harsh Agarwal Improve Article Tags : C Language Similar Reads C for Loop In C programming, the 'for' loop is a control flow statement that is used to repeatedly execute a block of code as many times as instructed. It uses a variable (loop variable) whose value is used to decide the number of repetitions. It is commonly used to iterate over a sequence such as an array or 4 min read C Program for Program for array rotation Write a function rotate(arr[], d, n) that rotates arr[] of size n by d elements.  Rotation of the above array by 2 will make array Recommended PracticeRotate ArrayTry It!Method 1 (Rotate one by one): leftRotate(arr[], d, n)start For i = 0 to i < d Left rotate all elements of arr[] by oneendTo ro 4 min read Snake and Ladder Game in C Snake and Ladder game is a traditional game that involves two or more players and the winner is the guy who reaches the final square on the game board at the earliest. Components of the GameA square board with a series of numbered squares arranged in m x m grid.A dice to be rolled usually uses a six 5 min read ES6 Loops Loops are the way to do the same task again and again in a cyclic way. A loop represents a set of instructions that must be repeated. In a loopâs context, a repetition is termed as an iteration. The following figure illustrates the classification of loops: Definite: There are three types of Definite 6 min read Loops in Programming Loops or Iteration Statements in Programming are helpful when we need a specific task in repetition. They're essential as they reduce hours of work to seconds. In this article, we will explore the basics of loops, with the different types and best practices. Loops in ProgrammingTable of Content What 12 min read Like