output

although fig was designed to teach 7 programming concepts, these concepts are common or illustrative to some degree in many, if not all programming languages. learning these concepts will help you understand python, bash, javascript and many others.

until output commands are used, variables and input commands only result in information being accessible to the program itself. it can store numbers, read a file, or get information from the keyboard, but it wont tell you anything. only the program will know, which is of little purpose to the user.

output commands let the program interact with the real world, and also with other programs. theyre often as simple as input commands.

the most famous output command is the print command. it is called this because before every computer had a screen, computers printed output on paper, with a computerised typewriter/printer called a teletype. also the word "print" means "to write out," and given a screen, the computer will "write out" to the screen.

here is a variable:

height

here we set the variable:

height 5

here we print the variable:

height 5 print

output is so important, that the most classic/famous programming example for beginners is called "hello world"-- which demonstrates output.

here is "hello world" in fig:

now "hello world" print

first we set the variable now to "hello world," then we print it. as a result, the words "hello world" show up on the screen.

the quotes in our code let the computer know the data is a string, but the quotes are not part of the string and are not displayed when the string is output.

the screen just says:

hello world

you can also change the colour of the output:

now = "hello world" ; colortext 5 ; print

we added = and ; to make the code debatably easier to read, but they are not required in fig. they show the variable now being set to "hello world" and they show that colortext is a different command, one that changes the colour of your text. in modern versions of fig, both "colortext" and "colourtext" do the same thing.

fig has 16 colours, which you do not need to memorise though if you change colours often enough you probably will memorise the table.

the table has two rows, and the first 8 colours (from 0 to 7) are:

0 black  1 blue         2 green         3 cyan         4 red         5 magenta  6 brown   7 white 

so colortext 5 means "change the colour to magenta."

the other row of colours are a brighter version of the first row:

0 black  1 blue         2 green         3 cyan         4 red         5 magenta  6 brown    7 white 

8 grey   9 light blue  10 light green  11 light cyan  12 light red  13 pink    14 yellow  15 bright white

fig did not create named commands for these colours, but you if you want to use names instead of numbers, variables let you do that.

simply add this code to the beginning of your program, and you can name the colours whatever you like:

black     = 0
blue      = 1
green     = 2
teal      = 3
red       = 4
purple    = 5
brown     = 6
offwhite  = 7
grey      = 8
skyblue   = 9
lime      = 10
turquoise = 11
tomato    = 12
pink      = 13
yellow    = 14
white     = 15

now = "r" ; colortext red     ; prints 
now = "a" ; colortext brown   ; prints 
now = "i" ; colortext yellow  ; prints 
now = "n" ; colortext lime    ; prints 
now = "b" ; colortext skyblue ; prints 
now = "o" ; colortext purple  ; prints 
now = "w" ; colortext blue    ; print ; colortext 7

the print command outputs text and then goes to the next line-- this is the default behaviour for many versions of the print command.

prints does the same thing as the print command, but stays on the same line.

variables, input and output make it possible for a coder to reference information, get information and offer information to the user.

basic-math and loops and conditionals make our programs more powerful and useful.

functions make our programs easier and faster to read and maintain.

- license: creative commons cc0 1.0 (public domain)

http://creativecommons.org/publicdomain/zero/1.0/