you can get a good “overview” of programming from (i use 7) basic fundamental concepts:
variables — essentally a name, plus a piece of data.
- assignment gives the name some data by mentioning the name and the data to assign:
- x = 5
- reference gets the data, just by using the name: x
- arrays and lists hold more than one piece of data, so in addition to the name you use a number: x
input — basically assigning a variable with data from a device, like a keyboard. or part of a file on the disk.
output — referencing a variable and putting its data onto a device, like a screen or a file on the disk.
basic math — unavoidable.
- you dont have to be really good with math.
- you can get the computer to do it for you.
- you still have to tell it what you want to do.
- much can often be abstracted with functions, but you will have to use numbers sometimes.
loops — think of a sandwich.
- the two pieces of bread mark the top and bottom of the loop.
- the “filling” is the code that runs (typically) more than once. can run once or 0 times.
- the bottom piece of bread usually doesnt do much.
- the top piece usually defines (briefly) how many times to loop, or what to wait for to stop.
- can be simulated with functions, but its more work.
conditionals — code that runs if something is true (or alternatively, runs if not true)
- can be simulated with a loop, because some loops can run (optionally) 0 times.
- are a sandwich, like the loop is.
- the bottom piece doesnt do much
- the top piece usually defines whether the filling code should run or not
- can be simulated with functions, but its more work
functions — basically assigning a name to a “paragraph” of program code
- can make it less work to name/keep track of all your variables
- can be called / used like any other command, so lets you “make your own commands.”
- kind of the staple unit of programming– like a bar of notes, or a paragraph of prose.
- the most difficult of these 7 concepts to really appreciate and understand– powerful but so deceptively simple, there has to be more to it (or it cant be that useful…)
variable = 5
# input: (in this example, get typing from keyboard)
variable = lineinput
# output: (the ; is optional and can be ignored.)
now variable ; print
# basic math:
x = variable plus 5
now “print keeps putting this on the screen!” print
variable = lineinput
ifequal variable, “hello”
now “hello yourself!” ; print
variable = “hey there” ; blank_the_screen ; print
# above line blanks the the screen and puts “hey there” at the top.
- license: creative commons cc0 1.0 (public domain)