24 Jan 2017

What is for loop in java?

First of all the question arises that, what is loop ..?   in simple way the doing same process multiple time is called loop as well in java "the execution of  a set of statements in multiple time is know as loop .  In java there are four types of loop exists :


  •  For loop
  • while loop
  • do-while loop
  • for each loop


Different types of loops have different ways to perform statement execution...🙂🙂🙂

So lets talk about the for loop syntax and their working process: 
 the syntax of for loop

for(initialization; condition; increment)
//statements execute if the conditions is true otherwise it escape from the loop 
{statements}

now how it works as you know about the  if-else condition with the help of boolean expression ,Similarly here the middle is condition ,  

  • first declare or initialize the value 
  •  it moves to the condition statement if the condition is true the statement is execute and then the increment part works and increase the value by one
  •  then again check the condition if true then execute the statement .
  •  JVM executes the statements under the for loop braces until the condition being false   
Lets assume an example of for loop...click me..😉😉



No comments:

Post a Comment