We learn how to convert Flowgorithm to BASH automatically,.. then we learn flowgorithm. It's damn .. easy language, even for the small kids, you know
The Integer data type is one of the most commonly used types in programming. An integer can store a positive or negative whole number, but can't store fractional values. So, it can store values such as 5, 42, 1947, but can't store numbers such as 3.2, 4.5, etc...
If a number with a fractional value is stored into a integer, the fractional value will be discarded. Hence, if 3.2 is stored into an integer, it will only retain 3.
The Variable Watch Window displays integers in blue.
The Real data type can store any number - both whole numbers and ones with fractional values. In many languages, this is called a "double" after the implementation standard known as "double-precision floating point".
The Variable Watch Window displays reals in purple.
The String data type is used to store any textual data. This includes words, letters, or anything else you would send in a text message. In programming, the text is delimited with double quotes. For example: "CSU, Sacramento", "computer", and "Year 1947" are all strings.
The Variable Watch Window displays strings in red.
The Boolean Data Type can store either "true" or "false". These are the basis of decision making in a computer program.
The Variable Watch Window displays Booleans in teal.
Data Type | Notes |
---|---|
Boolean | Stores either Boolean true or false |
Real | Stores a real number. |
Integer | Stores an integer number. |
String | Stores textual data. |
Any time you define a function or variable, it is given a unique name called an "identifier". To prevent identifiers from being confused with other items in an expression, they must follow a naming convention. Every programming language has one and they are fairly consistent from language to language.
In Flowgorithm, identifiers must adhere to the following rules:
Valid Identifiers | Notes |
---|---|
x | Identifiers can be single letter. |
noun2 | Numbers are allowed after the first letter |
Programming languages often make use of words such as "class", "public", and "if" for readability. Often, these overlap with the naming convention used by identifiers. So, in these cases, the word is considered "reserved" and cannot be used for Identifiers. Many programming languages also predefine functions and other constants and cannot be used.
Flowgorithm only has a few reserved words that are used in expressions.
and false mod not or pi true
To prevent confusion, the system doesn't allow identifiers to use the name of the data types.
boolean integer real string
Flowgorithm does not permit the names of intrinsic functions to be used.
abs cos random tan tostring
arccos int sgn tochar toreal
arcsin len sin tocode
arctan log size tofixed
char log10 sqrt tointeger
Future versions of Flowgorithm may expand the number of intrinsic functions. The following were reserved if, someday, they are added.
arccosh cosh
arcsinh sinh
arctanh tanh
The notation used for comparisons logical operators, etc... vary greatly between different programming languages. Flowgorithm supports the symbols used in mathmetics (using Unicode values) as well as the two major families of programming languages. The "BASIC-family" contains English keywords and operators. The "C-family" (which includes C, Java, C#) is far more symbolic.
Since mathematics and two major language families are supported, there are redundant operators. Flowgorithm considers the redundant operates as the same - and any set can be used (or all of them). This allows the student to use the operators that match the language they plan to to learn later.
Operator | C Family | BASIC Family | Mathematics (Unicode) |
---|---|---|---|
Equality | == |
= |
= |
Inequality | != |
<> |
≠ |
Less Than or Equal | <= |
<= |
≤ |
Greater Than Or Equal | >= |
>= |
≥ |
Logical Not | ! |
not |
¬ |
Logical And | && |
and |
∧ |
Logical Or | ` | ` | |
Multiply | * |
* |
× |
Divide | / |
/ |
÷ |
Modulo | % |
mod |
Flowgorithm also adds a few unique Visual Basic operators since if they have helpful, clearly defined, semantics
Name | Basic Family | Mathematics (Unicode) | Notes |
---|---|---|---|
String Concatenation | & |
C# and Java use the ambiguous "+ " operator for addition and concatenation. |
|
Exponent | ^ |
↑ |
Note: this is not a typical mathematical symbol, but is often used when superscripts cannot be used. |
In Java and C#, the +
operator is used for both string concatenation and addition. This can be quite confusing given the rather complex semantics. In Flowgorithm, addition will only work with numbers. The ampersand &
is used for concatenation. Also, C# and Java lack an exponent operator - instead relying their respective Math classes. Flowgorithm uses the Visual Basic's ^
.
The following are the precedence levels from high (evaluated first) to low.
Level | Name | Operators | Notes |
---|---|---|---|
8 | Unary | - ! not ¬ |
In Visual Basic, "not" precedence level is far lower -- above "and", but below all relational operators. |
7 | Exponent | ^ ↑ |
The exponent operator does not exist in C# or Java. |
6 | Multiply | * × / ÷ % mod |
Division will always be high-precision (floating point) |
5 | Addition | + - |
In Flowgorithm, "+ " will only work with numbers. |
4 | Concatenate | & | - |
3 | Relational | > < >= ≥ <= ≤ == = != <> ≠ |
- |
2 | Logical And | and && ∧ |
- |
1 | Logical Or | or ` |
Expression | Result | Notes |
---|---|---|
1 + 3 ^ 2 |
10 | |
`10 * 2 + 5 * 6 | 50 | |
10 * 2 and 5 * 6 have higher precedence than addition. The addition is done last. |
||
7 * (4 - 1) |
21 | Parenthesis are used for subexpressions, which are evaluated as a whole. |
6 / 3 * 2 |
4 | In mathematics, multiplication and division have the same precedence levels. So, they are evaluated left-to-right. The "PEMDAS" acronym, used in high-school, is a tad misleading. |
10 mod 3 |
1 | Modulo math gives the remainder from division |
10 % 3 |
1 | Same expression, but using the C-Family operator |
Function | Description |
---|---|
`Abs(n)`` | Absolute Value |
Arcsin(n) |
Trigonometric Arcsine |
Arccos(n) |
Trigonometric Arccos |
Arctan(n) |
Trigonometric Arctangent |
Cos(n) |
Trigonometric Cosine |
Int(n) |
Integral (whole value)` of a real number |
Ln(n) |
Natural Log |
Log(n) |
Natural Log (same as Ln)` |
Log10(n) |
Log Base 10 |
Sgn(n) |
Mathematical sign (-1 if n is negative, 0 if zero, 1 `if positive) |
Sin(n) |
Trigonometric Sine |
Sqrt(n) |
Square Root |
Tan(n) |
Trigonometric Tangent |
Function | Description |
---|---|
Len(s) |
Length of a string |
Char(s, i) |
Returns a character from the string *s *at index i. Characters are indexed starting at 0. |
Function | Description |
---|---|
ToChar(n) |
Convert a character code n into a character. |
ToCode(c) |
Convert a character c into a character code (integer) . |
ToFixed(r, i) |
Convert real number r to a string with i `digits after the decimal point. This function is useful for currency. |
ToInteger(n) |
Convert a string to an integer |
ToReal(n) |
Convert a string to an real |
ToString(n) |
Convert a number to a string |
Function | Description |
---|---|
EOF() |
Returns true of the end of the file was reached. This is used with files opened for reading. |
Random(n) |
A random number between 0 and (n - 1) |
Size(a) |
The size (number of elements) in an array |
Flowgorithm defines three commonly used constants. The constants true and false are often used to initialize Boolean variables. The constant pi is commonly used in mathematics.
Constant | Notes |
---|---|
true | Boolean True |
false | Boolean False |
pi | Mathematical Pi. Approximately 3.1415. |
π | Mathematical Pi. Same as the above. |
The Assignment shape is used to store the result of a calculation into a variable. This is one of the most common tasks found in programs.
XML
<?xml version="1.0"?>
<flowgorithm fileversion="3.0">
<attributes>
</attributes>
<function name="Main" type="None" variable="">
<parameters/>
<body>
<declare name="area" type="Real"
array="False" size=""/>
<declare name="radius" type="Integer"
array="False" size=""/>
<assign variable="radius" expression="7"/>
<assign variable="area"
expression="pi * radius ^ 2"/>
<output expression=
""The area is " & area"
newline="True"/>
</body>
</function>
</flowgorithm>
The example, to the right, declares two variables: area (which stores real numbers) and radius (which stores integers). It then uses an Assignment Statement to set the 'radius' to 7. Finally, it computes the area of a circle and stores the result in 'area'.
The Breakpoint Shape temporality halt the execution of the program. This is useful both for debugging programs and for demonstrations. Most professional software development applications have some form of the breakpoint.
The example, to the right, creates a variable called 'value' and assigns it an initial value of 12. The program then encounters a breakpoint shape - which still halt execution.
This will allow the user to see the current value of 'n' in the Variable Watch Window. Once execution is continued, the second assignment shape is executed.
A Call Statement transfers control to a function. Information being passed into the function are called 'arguments'.
The following example uses the Call Shape to execute a function called 'Greeting'.
When the program executes, the first shape will call the Greeting Function. After it outputs "Hello!", it will return and the Main Function and it will output "Goodbye!".
XML
<?xml version="1.0"?>
<flowgorithm fileversion="3.0">
<attributes>
</attributes>
<function name="Main" type="None" variable="">
<parameters/>
<body>
<call expression="greeting"/>
<output expression=
""Goodbye!""
newline="True"/>
</body>
</function>
<function name="Greeting" type="None" variable="">
<parameters/>
<body>
<output expression=""Hello""
newline="True"/>
</body>
</function>
</flowgorithm>
XML
<?xml version="1.0"?>
<flowgorithm fileversion="3.0">
<attributes>
</attributes>
<function name="Main" type="None" variable="">
<parameters/>
<body>
<declare name="i" type="Boolean"
array="False" size=""/>
<declare name="j" type="Boolean"
array="True" size="1"/>
<assign variable="i" expression="False"/>
<assign variable="j[0]" expression="False"/>
<output expression=
""before byval: " & i"
newline="True"/>
<call expression="byval( i)"/>
<output expression=
""after byval: " & i"
newline="True"/>
<output expression=
""before byref: " & j[0]"
newline="True"/>
<call expression="byref( j)"/>
<output expression=
""after byref: " & j[0]"
newline="True"/>
</body>
</function>
<function name="byval" type="None" variable="">
<parameters>
<parameter name="ai" type="Boolean" array="False"/>
</parameters>
<body>
<output expression=
""passed by value: " & ai"
newline="True"/>
<assign variable="ai" expression="True"/>
<output expression=
""changed to: " & ai"
newline="True"/>
</body>
</function>
<function name="byref" type="None" variable="">
<parameters>
<parameter name="ai" type="Boolean" array="True"/>
</parameters>
<body>
<output expression=
""passed by ref.: " & ai[0]"
newline="True"/>
<assign variable="ai[0]" expression="True"/>
<output expression=
""changed to: " & ai[0]"
newline="True"/>
</body>
</function>
</flowgorithm>
Comments don't affect how your program runs. They are used to include documentation about the program for other programmers. These can include: the logic of a loop, known issues, changes made, future changes, etc...
The example, to the right, contains a comment between two Output Shapes. It has no affect on the program.
XML
<?xml version="1.0"?>
<flowgorithm fileversion="3.0">
<attributes>
</attributes>
<function name="Main" type="None" variable="">
<parameters/>
<body>
<output expression=""Before the comment""
newline="True"/>
<comment text="Doesn't affect code execution."/>
<output expression=""After the comment""
newline="True"/>
</body>
</function>
<function name="Greeting" type="None" variable="">
<parameters/>
<body>
<output expression=""Hello""
newline="True"/>
</body>
</function>
</flowgorithm>
A Declare Statement is used to create variables and arrays. These are used to store data while the program is running. You can declare multiple variables by separating the names with commas.
See Assign
shape for details.
A Do Loop is similar to a While Loop except that the block of statements is executed at least once before the expression is checked.
The example, to the right, shows a Do Statement that accepts only a valid age as input. It will loop while the 'age' variable is less than 0 or greater than 110.
XML
<?xml version="1.0"?>
<flowgorithm fileversion="3.0">
<attributes>
</attributes>
<function name="Main" type="None" variable="">
<parameters/>
<body>
<declare name="age" type="Integer"
array="False" size=""/>
<output expression=
""Enter a valid age"" newline="True"/>
<do expression="age < 0 or age > 110">
<input variable="age"/>
</do>
</body>
</function>
</flowgorithm>
NOTE:
<do>
tag on the top of the loop specifies everything applied actually only near</do>
point
<do>
and </do>
tags embrace the loop body.
For Loops increment a variable through a range of values. This is a common, useful, replacement for a While Statement.
The example, to the right, prints the numbers from 1 to 100. The loop executes 100 times. The value of 'n' starts at 1 and increases by 1 each time the loop executes. The loop ends when 'n' reaches 100.
XML
<?xml version="1.0"?>
<flowgorithm fileversion="3.0">
<attributes>
</attributes>
<function name="Main" type="None" variable="">
<parameters/>
<body>
<declare name="n" type="Integer"
array="False" size=""/>
<for variable="n" start="1" end="100"
direction="inc" step="1">
<output expression="n" newline="True"/>
</for>
</body>
</function>
</flowgorithm>
An If Statement checks a Boolean expression and then executes a true or false branch based on the result.
The example, to the right, declares an integer called 'age'. It then reads the age from the keyboard.
Finally, an If Statement checks if the age is greater than or equal to 18. Based on this, it either takes the false branch and displays "Sorry, not yet", or takes the true branch and displays "Go vote!".
XML
<?xml version="1.0"?>
<flowgorithm fileversion="3.0">
<attributes>
</attributes>
<function name="Main" type="None" variable="">
<parameters/>
<body>
<declare name="age" type="Integer"
array="False" size=""/>
<output
expression=""Please enter your age""
newline="True"/>
<input variable="age"/>
<if expression="age >= 21">
<then>
<output expression=""Kegger!""
newline="True"/>
</then>
<else>
<output expression=""Milk!""
newline="True"/>
</else>
</if>
</body>
</function>
</flowgorithm>
An Input Statement reads a value from the keyboard and stores the result in a variable.
See Assign
shape for details.
An Output Statement evaluates an expression and then displays the result on the screen.
See Assign
shape for details.
A While Loop evaluates a Boolean expression and then, if true, executes a block of statements. After the statements are executed, the While Statementt rechecks the expression. When the expression is false, the loop ends.
The example, to the right, prints the numbers from 1 to 100. The assignment statement "n = n + 1" increments the variable 'n' by 1 for each iteration of the loop.
XML
<?xml version="1.0"?>
<flowgorithm fileversion="3.0">
<attributes>
</attributes>
<function name="Main" type="None" variable="">
<parameters/>
<body>
<declare name="n" type="Integer"
array="False" size=""/>
<assign variable="n" expression="1"/>
<while expression="n <= 100">
<output expression="n" newline="True"/>
<assign variable="n" expression="n + 1"/>
</while>
</body>
</function>
</flowgorithm>
The Forward Shape is used with the Turtle Graphics window. It moves the "turtle", an pen, forward a specified distance. If the pen is down, a line will be drawn. When up, the turtle moves without creating any mark.
<?xml version="1.0"?>
<flowgorithm fileversion="3.0">
<attributes>
</attributes>
<function name="Main" type="None" variable="">
<parameters/>
<body>
<forward expression="100" pen="down"/>
<turn expression="90" rotate="right"/>
<forward expression="100" pen="down"/>
<home/>
</body>
</function>
</flowgorithm>
None
The Home Shape is used in the Turtle Graphics window. It moves the turtle back to the starting (aka Home) position.
See Forward
shape for details.
The Turn Shape changes the current direction of the "turtle" in the Turtle Graphics Window. Measurements are in degrees.
See Forward
shape for details.
The Close Shape is used with file I/O. After a file is first opened, to read or write, it must be later closed.
Properties:
None.
See Forward
shape for details.
The Open Shape is used with file I/O. Before a file can be read from or written to, it must be opened first.
Properties:
XML
<?xml version="1.0"?>
<flowgorithm fileversion="3.0">
<attributes>
</attributes>
<function name="Main" type="None" variable="">
<parameters/>
<body>
<declare name="n" type="Integer"
array="False" size=""/>
<open expression=""squares.txt""
mode="write"/>
<for variable="n" start="1" end="1000"
direction="inc" step="1">
<write expression="n^2"/>
</for>
<close/>
</body>
</function>
</flowgorithm>
The Read Shape is used to retrieve a line of text from an opened file. The text is stored into a variable.
Properties:
Example
https://www.testingdocs.com/read-text-file-using-flowgorithm/
<?xml version="1.0"?>
<flowgorithm fileversion="3.0">
<attributes>
</attributes>
<function name="Main" type="None" variable="">
<parameters/>
<body>
<declare name="line" type="String"
array="False" size=""/>
<open expression=""input.txt""
mode="read"/>
<while expression="!EOF()">
<read variable="line"/>
<output expression="line" newline="True"/>
</while>
<close/>
</body>
</function>
</flowgorithm>
The Write Shape evaluates an expression and then stores it into an opened file.
Properties:
Example:
Flowgorithm creates the text file in the same directory as the flowchart program.
https://www.testingdocs.com/write-to-text-file-using-flowgorithm/
XML
<?xml version="1.0"?>
<flowgorithm fileversion="3.0">
<attributes>
</attributes>
<function name="Main" type="None" variable="">
<parameters/>
<body>
<declare name="i" type="Integer"
array="False" size=""/>
<assign variable="i" expression="1"/>
<open expression=""output.txt""
mode="write"/>
<while expression="i <= 10">
<write expression="i"/>
<assign variable="i" expression="i + 1"/>
</while>
<close/>
</body>
</function>
</flowgorithm>