HOW TO LEARN SOME BASH QUICKLY?

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

Image

BASICS

Data Types

Integer Data Type

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.

Image

Real Data Type

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.

Image

String Data Type

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.

Image

Boolean Data Type

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.

Image

Summary Chart

Data Type Notes
Boolean Stores either Boolean true or false
Real Stores a real number.
Integer Stores an integer number.
String Stores textual data.

Identifiers

Naming Rules

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:

Also note:

Examples

Valid Identifiers Notes
x Identifiers can be single letter.
noun2 Numbers are allowed after the first letter

Keywords

Overview

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.

Reserved Words

Flowgorithm only has a few reserved words that are used in expressions.

and  false  mod  not  or  pi  true

Data Type Keywords

To prevent confusion, the system doesn't allow identifiers to use the name of the data types.

boolean  integer  real  string

Illegal Keywords (used in functions)

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

Reserved for Future Use

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

EXPRESSIONS

Operators

About

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

Precedence

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 `

Examples

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

Intrinsic Functions

Mathematics

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

Strings

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.

Data Type Conversion

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

Other

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

Built-in Constants

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.

BASIC SHAPES

Assignment Shape

Default Appearance

Image

Properties

Image

What it Does

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.

Example

Image

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=
                       "&quot;The area is &quot; &amp; 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'.

Breakpoint Shape

Default Appearance

Image

Properties

Image

What it Does

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.

Example

Image

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.

Call Shape

Default Appearance

Image

Properties

Image

Modify arguments

Image

What it Does

A Call Statement transfers control to a function. Information being passed into the function are called 'arguments'.

Example

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!".

Image Image

XML

<?xml version="1.0"?>
<flowgorithm fileversion="3.0">
    <attributes>
    </attributes>
    <function name="Main" type="None" variable="">
        <parameters/>
        <body>
            <call expression="greeting"/>
            <output expression=
                      "&quot;Goodbye!&quot;" 
                    newline="True"/>
        </body>
    </function>
    <function name="Greeting" type="None" variable="">
        <parameters/>
        <body>
            <output expression="&quot;Hello&quot;" 
                    newline="True"/>
        </body>
    </function>
</flowgorithm>

Example 2. Passing arguments by value or by reference.

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=
                    "&quot;before byval: &quot; &amp; i" 
                    newline="True"/>
            <call expression="byval( i)"/>
            <output expression=
                    "&quot;after byval: &quot; &amp; i" 
                    newline="True"/>
            <output expression=
                    "&quot;before byref: &quot; &amp; j[0]"
                   newline="True"/>
            <call expression="byref( j)"/>
            <output expression=
                    "&quot;after byref: &quot; &amp; j[0]" 
                    newline="True"/>
        </body>
    </function>

    <function name="byval" type="None" variable="">
        <parameters>
            <parameter name="ai" type="Boolean" array="False"/>
        </parameters>
        <body>
            <output expression=
                    "&quot;passed by value: &quot; &amp; ai" 
                    newline="True"/>
            <assign variable="ai" expression="True"/>
            <output expression=
                    "&quot;changed to: &quot; &amp; ai"
                    newline="True"/>
        </body>
    </function>

    <function name="byref" type="None" variable="">
        <parameters>
            <parameter name="ai" type="Boolean" array="True"/>
        </parameters>
        <body>
            <output expression=
                    "&quot;passed by ref.: &quot; &amp; ai[0]"
                    newline="True"/>
            <assign variable="ai[0]" expression="True"/>
            <output expression=
                    "&quot;changed to: &quot; &amp; ai[0]" 
                    newline="True"/>
        </body>
    </function>

</flowgorithm>

Comment Shape

Default Appearance

Image

Properties

Image

What it Does

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

Example 1

Image

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="&quot;Before the comment&quot;"
                newline="True"/>
      <comment text="Doesn't affect code execution."/>
      <output expression="&quot;After the comment&quot;"
              newline="True"/>
    </body>
  </function>
  <function name="Greeting" type="None" variable="">
    <parameters/>
    <body>
      <output expression="&quot;Hello&quot;"
              newline="True"/>
    </body>
  </function>
</flowgorithm>

Declare Shape

Default Appearance

Image

Properties

Image

What it Does

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.

Example

See Assign shape for details.

Do Shape

Default Appearance

Image

Properties

Image

What it Does

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.

Example

Image

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=
              "&quot;Enter a valid age&quot;" newline="True"/>
            <do expression="age &lt; 0 or age &gt; 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 Shape

Default Appearance

Image

Properties

Image

What it Does

For Loops increment a variable through a range of values. This is a common, useful, replacement for a While Statement.

Example

Image

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>

If Shape

Default Appearance

Image

Properties

Image

What it Does

An If Statement checks a Boolean expression and then executes a true or false branch based on the result.

Example

Image

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="&quot;Please enter your age&quot;" 
                newline="True"/>
            <input variable="age"/>
            <if expression="age &gt;= 21">
                <then>
                    <output expression="&quot;Kegger!&quot;"
                            newline="True"/>
                </then>
                <else>
                    <output expression="&quot;Milk!&quot;"
                     newline="True"/>
                </else>
            </if>
        </body>
    </function>
</flowgorithm>

Input Shape

Default Appearance

Image

What it Does

An Input Statement reads a value from the keyboard and stores the result in a variable.

Properties

Image

Example

See Assign shape for details.

Output Shape

Default Appearance

Image

What it Does

An Output Statement evaluates an expression and then displays the result on the screen.

Properties

Image

Example

See Assign shape for details.

While Shape

Default Appearance

Image

What it Does

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.

Properties

Image

Example

Image

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 &lt;= 100">
                <output expression="n" newline="True"/>
                <assign variable="n" expression="n + 1"/>
            </while>
        </body>
    </function>
</flowgorithm>

GRAPHICS SHAPES

Forward Shape

Default Appearance

Image

Properties

Image

What it Does

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.

Example

<?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>

Home Shape

Default Appearance

Image

Properties

None

What it Does

The Home Shape is used in the Turtle Graphics window. It moves the turtle back to the starting (aka Home) position.

Example

See Forward shape for details.

Turn Shape

Default Appearance

Image

Properties

Image

What it Does

The Turn Shape changes the current direction of the "turtle" in the Turtle Graphics Window. Measurements are in degrees.

Example

See Forward shape for details.

FILE I/O SHAPES

Close Shape

Default Appearance

Image

What it Does

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.

Example

See Forward shape for details.

Open Shape

Default Appearance

Image

What it Does

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:

Graphical user interface, text, application Description automatically generated

Example

Image

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="&quot;squares.txt&quot;"
                  mode="write"/>
            <for variable="n" start="1" end="1000" 
                 direction="inc" step="1">
                <write expression="n^2"/>
            </for>
            <close/>
        </body>
    </function>
</flowgorithm>

Read Shape

Default Appearance

Image

What it Does

The Read Shape is used to retrieve a line of text from an opened file. The text is stored into a variable.

Properties:

Graphical user interface, text, application Description automatically generated

Example

https://www.testingdocs.com/read-text-file-using-flowgorithm/

Image

<?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="&quot;input.txt&quot;" 
                  mode="read"/>
            <while expression="!EOF()">
                <read variable="line"/>
                <output expression="line" newline="True"/>
            </while>
            <close/>
        </body>
    </function>
</flowgorithm>

Write Shape

Default Appearance

Image

What it Does

The Write Shape evaluates an expression and then stores it into an opened file.

Properties:

Graphical user interface, text, application, email Description automatically generated

Example:

Flowgorithm creates the text file in the same directory as the flowchart program.

https://www.testingdocs.com/write-to-text-file-using-flowgorithm/

Image

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="&quot;output.txt&quot;" 
                  mode="write"/>
            <while expression="i &lt;= 10">
                <write expression="i"/>
                <assign variable="i" expression="i + 1"/>
            </while>
            <close/>
        </body>
    </function>
</flowgorithm>