Loops
While Loops
While loops execute while the given conditional remains true. While loops use the same syntax as while loops in C# and Java.
The code will cease to execute once the given conditional is no longer true.
For Loops
For loops execute for a set, given length. A for loop will iterate through a range of given integers until the end of that range is reached. For loops are written the same was as in Java and C#.
For loops have the benefit of being able to keep track of how far something has looped through without the need for a separate variable by using the 'i', or however it may be named.
For loops do not need to strictly follow hard coded numbers and could loop through the length of an array or size of a list or to any integer value.
Iteration
Iteration is a key function of lists in Fantom. By using the 'listName.each' method, you are able to iterate through the length of the list and execute code for each item in that list. This can be done in reverse by using 'listName.eachr'.
Break
The break statement can be used in both while loops and for loops in order to stop the immediate loop in which it is contained.
Continue
The continue statement can be used in both for loops and while loops in order to jump back to the start of the loop. This can be paired with a conditional if statement in order to cause the loop to move onto the next iteration if a certain condition is met. This will only work on the immediate loop where the continue statement is located.




Comments
Post a Comment