About Gardener
Gardener is a simple programming language suitable for learning how to write programs. If you are new to programming, the Gardener language is the perfect place to start.
Gardener language allows you to control a gardener who can walk around the garden, planting and picking plants.
Using the Gardener language, you will now learn to execute commands, repeat commands multiple times, conditionally execute commands and create small subroutines (functions). These structures (statements) exist in almost every professional language, and understanding a simple language like Gardener will allow you to understand other languages more easily.
Gardener language is English only. Do not use letters, numbers, symbols, etc. that do not exist in English.
You can try running the educational examples below by clicking the execute button (play_circle) above the code example and see how the code works. It will change to silver while the programme is running and back to black when the programme has finished.
You can use playground to test your programming skills.
If you have any questions or suggestions, please send me a message.
Comment
Comments are parts of the program that are not executed, comments are ignored. Comments exist only for developers to document their code.
You can specify comments by double slash //. Everything on the line after // will be ignored.
Basic commands
Basic commands tell the gardener to do something (e.g. move forward, pick a plant). Each command must be on a separate line. Spaces before or after are ignored.
step
The step command moves the gardener one step forward in the direction the gardener is facing.
If the gardener is facing the wall, the programme will stop with an error.
turnLeft
The turnLeft command turns the gardener to the left.
plant
The plant command plants a plant at the location where the gardener is standing.
If the maximum number of plants is reached, the programme will stop with an error. The default maximum is 10.
pick
The pick command picks up a plant from where the gardener is standing.
If there is no plant to pick up, the programme will stop with an error.
You can use playground to test your programming skills.
Conditions
Conditions allow the developer to test whether something is true or false. All conditions have a similar format:
Conditions are created by:
- line with
ifkeyword, followed by space(s), followed by condition to test, followed by space(s), followed by opening curly bracket{ - list of commands or other conditions or other parts of the programme (zero or more)
- line with closing curly bracket
}
isWall
The isWall condition is true, if the gardener is facing a wall. Otherwise it is false.
isNorth
The isNorth condition is true, if the gardener is facing north (up). Otherwise it is false.
isPlant
The isPlant condition is true if there is a plant where the gardener is standing. Otherwise it is false.
not
not has a special meaning, it negates the condition.
E.g. not isWall condition is true, if the gardener is not facing a wall. Otherwise it is false.
You can use playground to test your programming skills.
repeat - repeat command multiple times
repeat statements allow the developer to repeat a statement multiple times.
repeat statement is created by:
- line with
repeatkeyword, followed by space(s), followed by number of repetition, followed by space(s), followed by opening curly bracket{ - list of commands or other conditions or other parts of the programme (zero or more)
- line with closing curly bracket
}
You can use playground to test your programming skills.
while - repeat command while condition is met
while statements allow the developer to repeat a statement while a condition is met.
while statement is created by:
- line with
whilekeyword, followed by space(s), followed by condition to test, followed by space(s), followed by opening curly bracket{ - list of commands or other conditions or other parts of the programme (zero or more)
- line with closing curly bracket
}
Conditions are the same as in if statements.
You can use playground to test your programming skills.
Functions
Functions represent multiple statements that can be defined as one command. E.g. Gerdener only knows `turnLeft` but does not know, how to turn back. You can create new command e.g. `turnBack` (that would be the function) and you can call this new command instead of calling `turnLeft` twice every time you want to turn back.
fnc statement is created by:
- line with
fnckeyword, followed by space(s), followed by function name, followed by space(s), followed by opening curly bracket{ - list of commands or other conditions or other parts of the programme (zero or more)
- line with closing curly bracket
}
Unlike other statements, functions are not executed until they are called. Functions are 'declared', which means they are just added to the language. You must call functions to execute them.
In the following example, nothing happens, the function is only declared but never called.
You must call the function to execute it.
You can use playground to test your programming skills.
Nesting
`Nesting` means placing statements in other statements. In following example there is repeat statement nested in while statement.
You can nest any statement inside any other statement. The only exception is functions, functions cannot be nested, they can only be declared at the top level. Following code would not work.
You can use playground to test your programming skills.