Skip to main content

Posts

Showing posts from February, 2020

Post 5: Repeated Action Syntax

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 c...

Post 4: Conditional Statements

Conditionals Conditionals in Fantom are comprised of if-statements, if-else statements, and switch statements. If-statements If-statements in Fantom remain virtually the same to if-statements in it's parent languages, Java and C#. The if-statement takes some form of conditional and will only perform the block of code inside of it IF the condition stated is true. Every if-statement will be checked if performed in a sequence, however if-else statements will stop once the first true condition is met and perform the nested code. Else will only be performed if none of the previous conditionals have been satisfied. Switch Statements Switch statements remain very similar to Java and C# as well, however with some syntax differences. A switch condition is declared at the start and is compared to the list of case labels below it, executing code when a condition is met. If none of the conditionals are met, there is a default condition that works like the else of and if-statement....

Post 3: Constants, Variables, and Arithmetic Operations

Constants, Variables, and Arithmetic Operations Variables Types Variables that would be considered primitives in Java (int, bool, float, etc.) are sub-classes of the Object class in Fantom. This allows them to contain various useful methods and allows for Fantom to remain fully object-oriented without sacrificing any performance gains from primitives. This follows the .NET standard of handling primitives. The Following are all of the Variable Types I will cover in this blog post: Bool Int Float Decimal Str Duration Uri Range List When declaring variables in Fantom, ':=' is used instead of '='. However, when updating a variables value, '=' should be used instead of ':='. Variables in Fantom don't need to be assigned a variable type during declaration. Both of these will compile fine: Integers The Integer variable type can hold any positive or negative whole number ranging from 9,223,372,036,854,775,807 to -9,223,3...