Note: if you haven’t yet installed 8th, please do so right now and follow the installation instructions as presented in the manual!
A “conditional” is a way of determining which of two (or more) paths to take. For example, if it’s the afternoon I may want to say “good afternoon”, while if it’s the morning I may want to say “good morning”. In 8th, the primary conditional words are if, else and then, and are used like so:
Using an alternative “conditional” called caseof makes this code easier to maintain and understand:
There are a few types of looping constructs in 8th:
- repeat… again — this is an “infinite loop”
- repeat… while — repeats as long as TOS is true
- loop and loop- — repeat a fixed number of times, counting up or down
- times — repeat a fixed number of times
You can break out of a looping construct by invoking break inside the loop. It will break out at the end of the current iteration, not immediately as in C or Java.
Try the following:
- Using “loop”, print the numbers from 1 to 10, with spaces in between
- Using “if… then” and “loop”, print the numbers from 1 to 10, and whether the number is even or odd (hint: use n:mod to determine the latter
- Using “caseof”, print the names of the numbers from 1 to 10
You’ve been on a whirlwind tour of 8th’s basic functionality. Now it’s time for you to delve deeper into the manual as well as explore the wealth of sample code provided with 8th. Don’t forget to join the 8th forum where you’ll find help and answers to most of your questions. Enjoy 8th!