java provides for three types of loops while loops the simplest kind of loop in java is while loop such loop tests that certain condition is satisfied and will perform the body of the loop each time this condition is evaluated to be true the syntax for such conditional test before loop body is executed is as followswhile (boolean_exploop_statement at the beginning of each iterationthe loop tests the expressionboolean expand then executes the loop bodyloop_statementonly if this boolean expression evaluates to true the loop body statement can also be block of statements considerfor examplea gnome that is trying to water all of the carrots in his carrot patchwhich he does as long as his watering can is not empty since his can might be empty to begin withwe would write the code to perform this task as followspublic void watercarrots (carrot current garden findnextcarrot ()while (!watercan isempty ()water (currentwatercan)current garden findnextcarrot ()recall that "!in java is the "notoperator for loops another kind of loop is thefor loop in their simplest formfor loops provide for repeated code based on an integer index in javawe can do that and much more the functionality of for loop is significantly more flexible in particularthe usage of for loop is split into four sectionsthe initializationthe conditionthe incrementand the body