Generally, the header part of the for loop decides (with initialization, condition, and incrementation) how many times the loop will be executed and the actual logic is placed in the body. We can have a for loop inside another for loop. Statement 1 If the condition is true, it enters the loop body and executes statementA. for(a=2; a<=b && a<=c; a++)       is valid, for(a=3; a<=b, a<=c; a++)             is not valid, for(a=4; a>=b || a>=0; a–)            is valid. These kinds of loops are used to travel through a set of elements strictly in an order (from beginning to ending). Wonderful way of teaching. All supposed conditions should be combined using. in Java Tutorials, Loops Java for loop Evolution Iteration is one of the most basic requirement in any programming language & of all, “for” is the most widely used loop in java for iteration. Loops are basically control statements. While loops are very important as we cannot know the extent of a loop everytime we define one. Java for loop provides a concise way of writing the loop structure. Your email address will not be published. Loops are used to execute a set of statements repeatedly until a particular condition is satisfied. All supposed conditions should be combined using AND or OR operators to make it a single condition (in C, we can have multiple conditions separated by commas and truth value of the last condition is considered as truth value of condition part). Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available. For loop have 3 sections, loop variable initialization, testing loop control variable, updating loop control variable. For loop syntax for( ; ; ){ ; } The initialization statement is executed before the loop starts. This example is a standard Java for loop. For example, the enhanced for loop for string type would look like this: Check out these java programming examples related to for loop: I really appreciate and recommend this website to all the beginners and experienced as well. Then control moves to condition part. Here is a simple Java for loop example: . All of them should be enclosed within curly braces. It should be like this 2. The below article on Java for loop will cover most of the information, covering all the different methods, syntax, examples that we used in for loops. for Loop Example Program In Java (Sum Of Numbers): This example finds the sum of all numbers till a given input number using for Loop In Java. Similarly, we can skip the incrementation part. ArrayList index starts from 0, so we initialized our index variable i with 0 and looped until it reaches the ArrayList size – 1 index. It is generally used to initialize the loop variable. This part is executed only once. This can be made possible by Java Labels for For Loops. class forLoopDemo { public static void main(String args[]) { // for loop 0begins when x=1 // and runs till x <=10 System.out.println("OUTPUT OF THE FIRST 10 N… But after reading the few tutorials on this website i realized that, my concepts weren’t that much clear which i feel have been cleared after hitting these tutorials. Java Labelled For Loop. If we use a dummy condition (just a; ) then it is treated as true. Duplication or Copying Our Site Content Is Strictly Prohibited. I think this array declaration is wrong.it can’t be like this. The Set of elements can be an array, an ArrayList, a LinkedList or any other collection. Because of the syntactical differences, their behavior may differ a little bit. Infinite loops make the program run indefinitely for a long time resulting in the consumption of all resources and stopping the system. int x=len;             is not valid as len is dead. The initialization step is setting up the value of variable i to 1, since we are incrementing the value of i, it would always be greater than 1 (the Boolean expression: i>1) so it would never return false. The condition part should result in a boolean value. The following are infinites. Using enhanced for loop. The initialization part can have any number of statements, but all of them should be separated by a comma. The Java for-each loop or enhanced for loop is introduced since J2SE 5.0. Your email address will not be published. It is mainly used to traverse the array or collection elements. We can have any number of statements in a for loop body. Iterating over the elements of a list is one of the most common tasks in a program. The traditional for loop was introduced in the first release of the Java language, and its simpler variation, for-each, was introduced in Java 5.Most developers prefer for-each for everyday iterations, but will still use for for things like iterating through a range or skipping values in a range.. When control comes to a Java for loop, it executes the initialization part first. There are three phases in the loop statement. This activity takes place only once. Java for Loop is used in programming to execute a set of codes repeatedly until the condition is true. We have 3. In the above example, the outer loop travels through an array of references (where each reference will refer an array) and the inner loop travels through each element (of the current array). So it comes to loop body to print “drink more water” and then it moves to increment a value by 1 so that a becomes 2. Statement 3 increases a value (i++) each time the code block in the loop has been executed. Java Program to find sum of natural numbers using for loop, Java Program to find factorial of a number using loops, Java Program to print Fibonacci Series using for loop. We can label each and every for loop in Java. The for-loop iterates over numbers. Inside the loop we print the elements of ArrayList using the get method.. So all the following usages are valid. Click the following links to check their detail. Java provides a way to use the “for” loop that will iterate through each element of the array. Java For Loop, is probably the most used one out of the three loops. This is one of the best sites for learning java. Third step: After every execution of for loop’s body, the increment/decrement part of for loop executes that updates the loop counter. The first stumbling block when we start learning any programming language is the concept of loops. Enhanced for loop can be used to iterate through Array or collections. i think first one was right . int len=p;             is valid, as len is treated as a fresh variable. In Java, the for-each loop is used to iterate through elements of arrays and collections (like ArrayList). Most runtime in programs is spent in loops. In this case, the variable x gets each value of the array (one value per iteration) and it is printed. Loops in Java are crucial when we want to execute the same block of code multiple times. The sample code is given below as well as the output. Thanks –, Very Helpful for beginners…As I am from a Non-IT background in my graduation, this site has helped me a lot…Add more sample & simple programs so that we can know more. To get the same result, we can use the following notation (for each style). Required fields are marked *, Copyright © 2012 – 2021 BeginnersBook . We will see the differences soon. He declared and FIXED the size of array to 4 and if I come to your point, you can declare any number of members in your array!. The condition should always result in a boolean value. For example, the enhanced for loop for string type would look like this: String arr[]={"hi","hello","bye"}; for (String str : arr) { System.out.println(str); } Check out these java programming examples related to for loop: Java Program to find sum of natural numbers using for loop; Java Program to find factorial of a number using loops Let’s take the same example that we have written above and rewrite it using enhanced for loop. This (inner loop) is repeated as long as the inner condition is true. Great going guys…keep it up :). Suppose we have an array and wanted to print each element of the array we can write a normal loop like the following. Java also includes another version of for loop introduced in Java 5. As i find it very ease in learning java, i’ve been in touch with the same for past 1yr but never been so comfortable with it. Once again the condition is true, so prints the message in the body and then comes to make a value 4. It also called: Java for each loop, for in loop, advanced loop, enhanced loop. In Java we have three types of basic loops: for, while and do-while. In the above example, in the initialization part, the variable a is initialized with 1. array ={2,11,45,9}; I want a real life example. We call this the control flow, or the flow of execution of the program. int [] array = new int[4]; The Java for loop repeats a set of Java operations. This is known as nesting. i– Decrement operation. There are often times when we need to use nested loops in Java and thus need to break the outer loop instead of the inner loop. For. Other types of values are not allowed. In the above program: The one-time activities associated with the loop (that too at the beginning) are done here. A for loop is useful when you know how many times a task is to be repeated. The advantage of the for-each loop is that it eliminates the possibility of bugs and makes the code more readable. A loop statement allows us to execute a statement or group of statements multiple times and following is the general form of a loop statement in most of the programming languages − Java programming language provides the following types of loop to handle looping requirements. Java for loop tutorial with examples and complete guide for beginners. A loop is a type of control statement which encircles the flow for a whilesomething like the vo… In the second example, just a semi-colon is the body of the loop. Here, generally, the control variables are incremented/decremented. All published articles are simple and easy to understand and well tested in our development environment. Always declare the size of array!. After executing the incr/decr part, the control comes to condition part. The trouble with for. It is ideal … Java for loop tutorial with examples and complete guide for beginners. Whatever we can do for a while we can do it with a Java for loop too (and of course with a. There is no limit on the number of constructs we can place in. The for loop is quite capable, but it has too many moving parts. For example if we are asked to take a dynamic collection and asked to iterate through every element, for loops would be impossible to use because we do not know the size of the collection. If we have only one statement, then the curly braces are optional. Such variable cannot be used outside the loop. A for loop is a repetition control structure that allows you to efficiently write a loop that needs to be executed a specific number of times. If we want to go the next iteration of a loop from the middle of the body (by skipping the remaining statements of current iteration) then we can use continue. If the condition is true, the loop will start over again, if it is false, the loop will end. As a program executes, the interpreter always keeps track of which statement is about to be executed. In case the header part itself has the actual logic implicitly then the body may not be required. Test condition: It will check for the condition against the counter variable.If the condition is True, the compiler will execute the statements inside the for loop. Table of Contents [ hide] For loop combines three elements which we generally use: initialization statement, boolean expression and increment or decrement statement. The below article on Java for loop will cover most of the information, covering all the different methods, syntax, examples that we used in for loops. When we create a variable at initialization part of the for loop that variable is automatically dead when the loop ends (in C, we cannot create a variable at initialization part of the for loop). In this tutorial, I’ll show how to declare, populate, and iterate through Java string arrays, including the newer for-loop syntax that was introduced with Java 5. Sometimes the initialization takes place by the time control comes to the for loop, in that case, we can write a dummy statement (just a semi-colon) at initialization part. Privacy Policy . But the condition part should not be separated by commas. Source code in Mkyong.com is licensed under the MIT License , … We can place any construct inside another a for loop. What Are Java Loops – Definition & Explanation. If the condition results in true, the control enters the body. Enhanced for loop provides a simpler way to iterate through the elements of a collection or array. Here is the code for the array that we had declared earlier- for (String strTemp : arrData) { System.out.println (strTemp); } You can see the difference between the loops. Then control comes to initialization part of inner loop and then to condition part. If the condition part is true, it enters the body of loop body and executes statementB. See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases. The name of the class is forLoopDemo. In that case, we can have a dummy body. At initialization, we can create, In this example, the loop is repeated for 4 times (number of, Similar to normal loop, we can come out of this loop also using a statement like, Java: Validating a Phone Number Format String | Java Programs, Java Code to Calculate Years Between Two Dates | Java Programs, Java: VAT Calculator Program In 2 Ways | Java Programs, Java Program Calculate Profit and Loss | Java Programs, Simple Java Program Internet Speed Test | Java Programs, Java: Convert Minutes To Seconds & Vice Versa | 4 Simple Ways, Java: Convert Hours To Seconds & Minutes | Vice Versa, Java Number Of Words In A String | 4 Ways, Java Program To Calculate Salary Of An Employee | 3 Ways, Java Mortgage Payment Calculator in 3 Ways | Java Programs, Java Program To Calculate Modulus | Mod Java, Java Standard Deviation in 4 Easy Ways | Java Programs, Java Distance Traveled By Vehicle Program | 4 Ways, Mean Java Program In 4 Simple Methods | Java Programs, 4 Ways To Calculate Mode In Java | Java Programs, Java Program To Calculate Median Array | 4 Methods, 4 Methods To Find Java String Length() | Str Length, Java Code For log() – 4 Simple Ways | Java Codes, Java Code to Calculate Love Percentage [FLAMES] | Programs, [GUI] Implement Simple Calculator Using JFrame/Swing In Java | Programs, Java Program to Calculate Income Tax | Java Programs, Java Code to Calculate Harmonic Value | Java Programs, Java Program to Calculate Hypotenuse Of Triangle | Programs, 4 Ways To Find Height of A Binary Tree In Java | Java Programming, Java: Volume Of Box Program | Java Programs, Java: Number of Days In A Month – 3 Ways | Java Programs, C Programs – 500+ Simple & Basic Programming Examples & Outputs, C Program Inverted Right Triangle Star Pattern – Pattern Programs, C Program To Delete An Element From An Array At Specified Position | C Programs, C Program Right Triangle Star Pattern | Pattern Programs, C Mirrored Right Triangle Star Pattern Program – Pattern Programs, C Plus Star Pattern Program – Pattern Programs | C, C Pyramid Star Pattern Program – Pattern Programs | C, C Square Star Pattern Program – C Pattern Programs | C Programs, Hollow Square Pattern Program in C | C Programs, C Program To Find Maximum & Minimum Element In Array | C Prorams, C Program To Search All Occurrences Of A Character In String | C Programs, C Program To Remove First Occurrence Of A Character From String, C Program To Count Frequency Of Each Character In String | C Programs, C Program To Reverse Words In A String | C Programs, C Program To Left Rotate An Array | C Programs, C Program To Delete Duplicate Elements From An Array | 4 Ways, C Program To Print All Unique Elements In The Array | C Programs, C Program To Count Number Of Even & Odd Elements In Array | C Programs, C Program Count Number Of Words In A String | 4 Ways, C Program Number Of Alphabets, Digits & Special Character In String | Programs, C Program To Compare Two Strings – 3 Easy Ways | C Programs, C Program To Copy One String To Another String | 4 Simple Ways, C Program To Remove Blank Spaces From String | C Programs, C Program To Find First Occurrence Of A Word In String | C Programs, C Program To Count Occurrences Of A Word In A Given String | C Programs, C Program To Search All Occurrences Of A Word In String | C Programs, C Program To Remove First Occurrence Of A Word From String | 4 Ways, C Program To Remove Repeated Characters From String | 4 Ways, C Program To Copy All Elements From An Array | C Programs, C Program To Find Last Occurrence Of A Character In A Given String, C Program To Remove Last Occurrence Of A Character From String, C Program Find Maximum Between Two Numbers | C Programs, C Program To Toggle Case Of Character Of A String | C Programs, C Program To Concatenate Two Strings | 4 Simple Ways, C Program To Find Last Occurrence Of A Word In A String | C Programs, C Program To Replace Last Occurrence Of A Character In String | C Programs, C Program To Trim White Space Characters From String | C Programs, C Program To Trim Trailing White Space Characters From String | C Programs, C Program To Trim Leading & Trailing White Space Characters From String, C Program To Remove All Occurrences Of A Character From String | C Programs, C Program Replace All Occurrences Of A Character With Another In String, C Program To Find First Occurrence Of A Character In A String, C Program Replace First Occurrence Of A Character With Another String, C Program To Find Reverse Of A string | 4 Ways, C Program To Check A String Is Palindrome Or Not | C Programs, C Program To Count Occurrences Of A Character In String | C Programs, C Program To Find Lowest Frequency Character In A String | C Programs, Highest Frequency Character In A String C Program | 4 Ways, C Program To Sort Even And Odd Elements Of Array | C Programs, C Program To Convert Lowercase String To Uppercase | 4 Ways, C Program To Convert Uppercase String To Lowercase | 4 Ways, C Program Count Number Of Vowels & Consonants In A String | 4 Ways, C Program To Count Frequency Of Each Element In Array | C Programs, Merge Two Arrays To Third Array C Program | 4 Ways, C Program Count Number of Duplicate Elements in An Array | C Programs, C Program To Right Rotate An Array | 4 Ways, C Program To Find Length Of A String | 4 Simple Ways, Rhombus Star Pattern Program In C | 4 Multiple Ways, C Program To Sort Array Elements In Ascending Order | 4 Ways, C Program To Sort Array Elements In Descending Order | 3 Ways, C Program To Count Number Of Negative Elements In Array, C Program To Insert Element In An Array At Specified Position, C Program To Read & Print Elements Of Array | C Programs, C Program To Search An Element In An Array | C Programs, C Program To Put Even And Odd Elements Of Array Into Two Separate Arrays, C Program To Print All Negative Elements In An Array, C Program To Find Sum Of All Array Elements | 4 Simple Ways, C Program Hollow Inverted Mirrored Right Triangle, Diamond Star Pattern C Program – 4 Ways | C Patterns, Hollow Inverted Pyramid Star Pattern Program in C, C Program Half Diamond Star Pattern | C Pattern Programs, C Program To Print Number Of Days In A Month | 5 Ways, C Program Hollow Inverted Right Triangle Star Pattern, C Program Hollow Mirrored Rhombus Star Pattern | C Programs, Left Arrow Star Pattern Program in C | C Programs, Right Arrow Star Pattern Program In C | 4 Ways, C Program Hollow Mirrored Right Triangle Star Pattern, 8 Star Pattern – C Program | 4 Multiple Ways, C Program To Input Week Number And Print Week Day | 2 Ways, One Dimensional Array In Java – Tutorial & Example, Two Dimensional Array In Java – JavaTutoring, Multi Dimensional Array In Java – Tutorial & Program, Java Program To Check Even Numbers | 4 Ways, Java Program To Calculate EMI – Monthly & Annum, Java Program To Calculate Exponent Value | 4 Ways, C Program Mirrored Half Diamond Star Pattern | C Patterns, C Program Inverted Mirrored Right Triangle Star Pattern, C Program Hollow Right Triangle Star Pattern, Java Program To Calculate Future Investment Value, Volume Of Cube Java Program – 2 Ways | Programs, Java Program Calculate Perimeter Of Circle | 4 Simple Ways, Java Program Perimeter Of Equilateral Triangle | Programs, Java Program Calculate Perimeter Of Parallelogram | 3 Ways, Java Program To Find Perimeter Of Rectangle | 3 Ways, Java Program Calculate Perimeter Of Square | Programs, Java Program To Calculate Perimeter Of Rhombus | 3 Ways, HCF Of Two & N Numbers Java Program | 3 Ways, LCM Of Two Numbers Java Program | 5 Ways – Programs, Java Program Convert Fahrenheit To Celsius | Vice Versa, Java Program Count Vowels In A String | Programs, Square Star Pattern Program In Java – Patterns, Java Right Arrow Star Pattern Program | Patterns, Rhombus Star Pattern Program In Java – Patterns, Reverse A Number In Java – 4 Simple Ways | Programs, Java Pyramid Star Pattern Program | Patterns, Plus Star Pattern Java Program | Patterns, Perfect Number In Java Program – 3 Ways | Programs, Palindrome Program In Java – 5 Ways | Programs, Java Mirrored Right Triangle Star Pattern Programs | Patterns, Merge Sort Java – Program 2 Ways | Sortings, Java Mirrored Half Diamond Star Pattern Programs | Patterns, Left Arrow Star Pattern Java Program – Patterns, 30+ Number & Star Pattern Programs In Java – Patterns, Java Program To Display Transpose Matrix | 3 Ways, Java Program To Subtract Two Matrices – 3 Ways, Java Program To Check Leap Year Or Not – 4 Ways, GCD Of Two Numbers In Java – Programs | 5 Ways, Prime Number Java Program – 1 to 100 & 1 to N | Programs, Java Program For Addition, Subtraction, Multiplication, Division | Programs, Java Program Sum Of digits Of A Number | Programs, Java Program To Reverse An Array | Programs, Java Program To Insert An Element In Array | Programs, Linear Search In Java Program – 2 Simple Ways | Programs, Java Program to Add Two Matrices – 4 Ways | Programs, Selection Sort Java – Algorithm 2 Ways | JavaSorting, Implement Bubble Sort Java – Algorithm | 2 Easy Ways, Java Half Diamond Star Pattern Program | Patterns, Hollow Diamond Star Pattern Java Program | Patterns, Java Inverted Right Triangle Star Pattern Program | Patterns, Java Hollow Inverted Pyramid Star Pattern Program, Java Hollow Pyramid Star Pattern Program | Patterns, Java Hollow Inverted Mirrored Right Triangle Star Pattern, Java Inverted Mirrored Right Triangle Star Pattern, QuickSort Java – Algorithm | 2 Simple Ways, Insertion Sort Java Algorithm – 2 Ways | Java Sortings, Implement Heap Sort Java Algorithm – 2 Ways | Java Sorting, Hollow Inverted Right Triangle Star Pattern Java Program, Hollow Mirrored Right Triangle Star Pattern, Fibonacci Series In Java Program – 4 Multiple Ways, C Program Find Circumference Of A Circle | 3 Ways, C Program Area Of Trapezium – 3 Ways | C Programs, C Program Area Of Rhombus – 4 Ways | C Programs, Hollow Right Triangle Star Pattern Java Program, Inverted Pyramid Star Pattern Java Program, Matrix Multiplication In Java – 4 Ways | Programs, 8 Star Pattern Java Program – 4 Ways | Programs, Reverse A String In Java – 4 Ways | Programs, X Star Pattern C Program 3 Simple Ways | C Star Patterns, C Program Hollow Diamond Star Pattern | C Programs, Mirrored Rhombus Star Pattern Program In c | Patterns, Hollow Rhombus Star Pattern Program In C | Patterns, C Program To Find Area Of Semi Circle | C Programs, C Program Area Of Parallelogram | C Programs, C Program Area Of Isosceles Triangle | C Programs, Java Program To Print Mirrored Rhombus Star Pattern | Programs, Java Program To Print Hollow Mirrored Rhombus | 4 Ways, Java Program To Print Diamond Star Pattern | Programs, Java Programs – 500+ Simple & Basic Programming With Outputs, Armstrong Number In Java Program – 5 Simple Ways, Java Program To Convert Decimal To Binary | Vice Versa, Java Program To Convert Decimal To Octal | Vice Versa, Java Program Convert Decimal To Hexadecimal | Vice Versa, Java Program Sum Of N Numbers | 4 Simple Ways, Java Program Addition Of Two Numbers – 4 Ways | Programs, Java Program To Convert Octal To Hexadecimal | Vice Versa, Java Program To Check Vowel Or Consonant | 5 Ways, C Program Check A Character Is Upper Case Or Lower Case, C Program To Count Total Number Of Notes in Given Amount, C Program To Calculate Perimeter Of Rhombus | C Programs, C Program To Calculate Perimeter Of Rectangle | C Programs, C Program To Calculate Perimeter Of Square | C Programs, C Program To Find Volume Of Cone | C Programs, C Program To Calculate Volume Of Cube | C Programs, C Program Volume Of Cylinder | C Programs, C Program Area Of Equilateral Triangle | C Programs, Curved Surface Area Of Cube : Java Program | 3 Simple Ways, Java Program Calculate Total Surface Area Of Cylinder | 3 Ways, Java Program To Calculate Average Marks | 5 Methods, Compound Interest : Java Program In 5 Simple Ways | Programs, Java Program To Calculate CGPA Percentage | 3 Simple Ways, Java Program : Calculate Batting Average Example | Programs, Java Program To Calculate Depreciation | Programs Hub, Java Program To Calculate Power Of Number | 4 Ways, Java Program To Calculate Commission Percentage | Programs, Java Program To Calculate Distance Between Two Points | 3 Ways, Java Program To Calculate Discount Of Product | Programs, Java Program To Calculate Average Of N Numbers, Java Program To Calculate Electricity Bill | Example, Factorial Program In Java – 5 Simple Ways | Java Tutoring, Total Surface Area Of Sphere Java Program | Programs, Volume Of Cone Java Program In 4 Simple Ways | Programs, Java Program Volume Of Cylinder | 3 simple ways, Java Program To Calculate Volume Of Prism | 3 Simple ways, Java Program To Calculate Volume Of Sphere – 3 Simple Ways, Java Program To Calculate Area Of Rhombus | 4 Ways, Java Program To Find Area Of Rectangle | 3 Ways, Java Program To Calculate Area Of Triangle – 5 Ways, Java Program To Find Area of Parallelogram – Programs, Java Program To Find Area Of Isosceles Triangle, Java Program To Find Area Of Equilateral Triangle, Java Program To Calculate Area Of Circle | 5 Ways, Java Program Calculate Remainder | Java programs, control comes out of the java for loop and executes the statement, Java Program Calculate Distance Between Two Points. Thus it is important to see the co-ordination between Boolean expression and increment/decrement operation to determine whether the loop would terminate at some point of time or not. Whatever we can do for a while we can do it with a Java for loop too (and of course with a do-while too). In a Java for loop, initialization is executed only once irrespective of a number of times the loop is executed. The basic “for” loop was enhanced in Java 5 and got a name “for each loop”. We have 3 types of looping constructs in Java. When the condition is true, the loop body is executed. Statement 2 defines the condition for the loop to run (i must be less than 5). Java For Loop The Java for loop is used to iterate a part of the program several times. Statement 1 sets a variable before the loop starts (var i = 0). Java Code Editor: for(int i=0; i < 10; i++) { System.out.println("i is: " + i); } . Note: In the above example, I have declared the num as int in the enhanced for loop. Enhanced ‘for’ Loop: The Java SE 5 extends the basic for loop to increase the readability of the loop. It provides an alternative approach to traverse the array or collection in Java. int arr[]={2,11,45,9}; Both ways are correct. Comments Off on Java For Loop – Tutorial With Examples | Loops. This will change depending on the data type of array. Java for Loop In this tutorial, we will learn how to use for loop in Java with the help of examples and we will also learn about the working of Loop in computer programming. i>1 is condition(Boolean expression) Relatively this approach (foreach) is comfortable to visit all elements of the list. While loop in Java. Enhanced for loop is useful when you want to iterate Array/Collections, it is easy to write and understand. You can right like this : In this tutorial, we're going to review different ways to do this in Java. The above three different java loops are used primarily with same purpose and the difference is in their syntax. It runs from 1 to 10 generating all the natural numbers in between. Then the condition results in false (as 4<=3 is false) and comes out to execute the statement after the loop. A for loop is a special loop that is used when a definite number of loop iterations is required. Thank you so much! Once the condition returns false, the statements in for loop does not execute and the control gets transferred to the next statement in the program after for loop. Executing a set of statements repeatedly is known as looping.