Guest Apogee Posted April 14, 2014 Share Posted April 14, 2014 I saw "For" recently.I know somewhat of what it means, but i don't understand why you would need to use it. Can somebody elaborate? Link to comment Share on other sites More sharing options...
Joseph Posted April 14, 2014 Share Posted April 14, 2014 The for keyword is meant to loop through an array/list Link to comment Share on other sites More sharing options...
FrostBug Posted April 14, 2014 Share Posted April 14, 2014 (edited) There are 2 types of for loops; The 'standard' for loop which loops through a code block while a condition is true, executing some logic after every loop as well (usually incrementation). example: for(int i = 0; i < 10; i++) { //Code block } this would execute the code block until the variable i is no longer less than 10; And will increment i by one after each execution of the code block. This type of for loop is commonly used for iterating through arrays of primitive types, grabbing elements by index. another variation of the for loop (often referred to as a for-each loop) is used to pull elements out of a collection. This type of for-loop will only work with collections that implement the Iterable interface, and is essentially a limited iteration by the collections iterator. for(Object element : collection) { //Do something with the elementa } Edited April 14, 2014 by FrostBug 1 Link to comment Share on other sites More sharing options...
Jams Posted April 14, 2014 Share Posted April 14, 2014 The for keyword is meant to loop through an array/list nice 1111 posts, lel Link to comment Share on other sites More sharing options...
Guest Apogee Posted April 15, 2014 Share Posted April 15, 2014 Hey, Thanks Link to comment Share on other sites More sharing options...
Deffiliate Posted April 16, 2014 Share Posted April 16, 2014 For loops are a powerful tool my friend. Learn them, and you will love them. Link to comment Share on other sites More sharing options...
Joseph Posted April 16, 2014 Share Posted April 16, 2014 Also enums 1 Link to comment Share on other sites More sharing options...