constructjava provides shorthand notation for such loopscalled the for-each loop the syntax for such loop is as followsfor (type name expressionloop statement where expression evaluates to collection that implements the java lang iterable interfacetype is the type of object returned by the iterator for this classand name is the name of variable that will take on the values of elements from this iterator in the loop_statement this notation is really just shorthand for the followingfor (iterator it expression iterator()it hasnext()type name it next()loop_statement for exampleif we had listvaluesof integer objectsand values implements java lang iterablethen we can add up all the integers in values as followslist values/statements that create new values list and fill it with integers int sum for (integer valuessum + /unboxing allows this we would read the above loop as"for each integer in valuesdo the loop body (in this caseadd to sumin addition to the above form of for-each loopjava also allows for-each loop to be defined for the case when expression is an array of type typewhichin this casecan be either base type or an object type for examplewe can total up the integers in an arrayvwhich stores the first ten positive integersas followsint[ { }