Indentation

ASnake Documentation

Table Of Contents

Summary:

Indentation also known as whitespace, is used as control flow for when statements and block of code executes.

Syntax:

You can use spaces or tabs.

It is best to keep the number of tabs or spaces consistent per block, though ASnake does attempt to interpret inconsistent indentation and will not throw a compile error.

However, there are also written keywords to end a statement.

Here is a list of its syntax aliases:

  1. then
  2. do
  3. ;
  4. end

The end keyword will deindent a statement one level, while the others will attempt to keep the indent level the same.

Indentation is defined by a block start and a block end determinine what section a code will be optionally executed.

The following will trigger a block start:

  1. Conditionals: if elif else
  2. Loops: while for loop
  3. Function defines: def does
  4. Class defines: class

And to a minor extent, type wraps.

Here is an example via conditional:

if x greater than y
    print 1
    print 2

It will only output 1 and 2 if x is greater than y.

For a way to do this in one line, we can use then syntax, and it's aliases:

if x greater than y do print 1 then print 2

However, to show that the amount of indentation matters, let's create an example where print 2 is unindented.

if x greater than y
    print 1
print 2

This will output 2 regardless of if print 1 triggers, because it is at the outermost scope.

To recreate this on one line, we can use end syntax.

if x greater than y do print 1 end print 2

Which, as before, will always output 2 regardless of if 1 triggers.

Python's colon is typically used to start code blocks and end the prior statement. That is not required in ASnake, it is optional.

def thing1():
    print 1
def thing2()
    print 2
thing1 ; thing2

Both output properly.

Ignore Indentation

If you don't want indentation at all, you can turn it off using a meta. However, you must end every block with an end to indicate the block is over. A new line indicates a new statement, but you can use ; and Python's : too.

$ignoreIndentation
if True
print 1
print 2
end

For those who complain that Python lacks curly-braces, ASnake provides a nice little meta alias for you:

$ignoreIndentation
if True ${ 
    print 12
    if False ${ print 21 $}
 $}

The $ is required, otherwise it will be interpreted as syntax for a set. Ignore indent meta is also required to be on.

Python IDLE Formatting:

Sometimes you may come across web pages with examples of Python code with >>> and ... at the start of each line. Copy and pasting that only to get errors is confusing and annoying, so ASnake accepts it as valid syntax.

>>> if 12 > 4:
...   print('no problem.')
... # result: no problem.

If you are confused what this is, you can experience it by entering Python's REPL (usually activated by just writing your python command bare with no arguments). A new line is started via >>>, and if there is indentation indicating you are inside a code block, the line is started via .... This is generated automatically by Python's REPL, so no need to enter it yourself.

This ASnake feature is merely a quality-of-life convenience, and should cause less confusion for less-experienced Python coders.

Scroll to top