digital literacy for everyone



[lit] although quasi 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. [[variables]] | [[input]] | [[output]] | [[basic-math]] | [[loops]] | /conditionals/ | [[functions]] conditionals are one of the most native computing concepts-- if two values compare, branch to a specific location in code. for conditionals in quasi, as with loops, you mark the top of the code to be run conditionally, and the bottom of the code to be run conditionally. [url][url] username "getting username from url... " prints username command str print now ifequal username "bobby" now = "you have mail." print next the code between the ifequal line and next runs only if the person types in "bobby" as their username. of course the program should also check for a matching password, and probably do something different if there is no email waiting for bobby. conditionals also make the break command useful. lets go back to one of our examples from the previous section on [[loops]]: f "1 litre milk|1 dozen eggs|2 kg sugar" f split f "|" # create array each = forin f each ; print next we can tell it to count to a fixed number, but its smarter than that. we can tell it to look for a certain item and stop there: f "1 litre milk|1 dozen eggs|2 kg sugar" f split f "|" # create array each = forin f each ; print now ifequal each "1 dozen eggs" now break next next we added this conditional: now ifequal each "1 dozen eggs" now break next its ok that conditionals end with *next*; quasi translates next to "{" and javascript knows which { is which. running the program, the output looks like this: 1 litre milk 1 dozen eggs you can also make it look for "eggs" in any string without the exact match. we can also use ifmore and ifless to check other conditions. but for comparing numbers, you want to convert *command* input (always an array of strings) to a number first: r = randint 1 10 now "guess a number between 1 and 10 in the url:" print now " goes here" print now "" print now "you guessed:" prints now command str int print say "it was actually:" plus r print now ifmore now r now "too high!" print next now ifless now r now "too low!" print next now ifequal now r now "thats right!" print next [[functions]] let you make your own commands.
back to quasi concepts: [url][url] quasi main page: [url][url] home: [lit][lit]