Skip to content
NonstickAtom785 edited this page Jan 14, 2020 · 5 revisions

Note this page is still in development bug @NonstickAtom785 or @Zeda to get this finished.

Control Flow

If you already know how to use BASIC control flow you can skip to the next section on Grammer's control flow perks. If not, then read up on this section before moving on. There is a lot of info to retain.

Control Flow is the ability to control the flow of your program. We do this by using commands such as If, While, Repeat, For, and Goto/Lbl.

Code Blocks and Loops

Using If-Then-Else

If I use If in a program Then, if the statement is true then the following code will be executed until the corresponding End token is reached.

Code:

If 1
Then
<<<code to execute>>>
End

Note: In Grammer, true simply means non-zero, while 0 is false, as in TI-BASIC.

However, as in TI-BASIC, if we only need to execute one line of code, Then and End can be omitted.

Code:

If 1
<<<code to execute>>>

If I use an If, Then, and Else in a single block then if the statement is true, the following code will be executed until the Else token. If the statement is false the code under Else will be executed until the corresponding End token is reached.

Code:

If 0
Then
<<<code to execute if true>>>
Else
<<<code to execute if false>>>
End

A statement is any block of math to be used after the If. I used 1 and 0 as to represent not just how If sees the equation but all control flow commands. However, you can use a variable such as A or an expression like A>1 which would return 1 if A is greater than 1 and 0 if less than A.

While loops

'While is expressed in Grammer just like it is in BASIC. The syntax isWhile <<>>. This is a type of loop that executes the code inside of its block _while_ the expression is true. If the expression is not true then the whole block is skipped and the program continues executing after the End`.

Code:

.0:Return
While 1
ClrDraw
Text(<sub>o<sub>"Hi there!
DispGraph
End
Stop

This code will continue to clear the graph screen then display the text "Hi there!" forever, unless you break it by pressing [ON].

Instead of using just numbers we can get more control over the flow of the program if we use a pvar and modify it.

Code:

.0:Return
42→L
While L       ;While L is a true statement(not equaling 0) then execute the following code.
If getKey(15
0→L
End
Stop

But that's not all! You can also use commands that return an output.

While pixel-Test(0,0
GetInc(B
If B
##Place holder. Get back to this.

Repeat loops

For loops

Pause If

Labels and Subroutines

Lbl

Return

Goto

▶Nom(

Line Jumping With ln(

prgm

Passing Parameters

Asm(

AsmPrgm

Others

Pause

expr(

Interrupts

Execute a line of code

Clone this wiki locally