Simple Statements
In AVAP, a simple statement consists of a single logical line. Multiple simple statements can be placed on a single line, separated by semicolons. The syntax for simple statements is:

simple_stmt ::=  expression_stmt | assert_stmt | assignment_stmt | augmented_assignment_stmt | annotated_assignment_stmt | pass_stmt | del_stmt | return_stmt | yield_stmt | raise_stmt | break_stmt | continue_stmt | import_stmt | future_stmt | global_stmt | nonlocal_stmt | type_stmt
Here’s a brief overview of each type of simple statement:

Expression Statement (expression_stmt): Executes an expression, which can be used for operations or calling functions.
Assert Statement (assert_stmt): Used for debugging purposes to test conditions.
Assignment Statement (assignment_stmt): Assigns values to variables or data structures.
Augmented Assignment Statement (augmented_assignment_stmt): Performs an operation on a variable and assigns the result back to the variable (e.g., x += 1).
Annotated Assignment Statement (annotated_assignment_stmt): Used for assigning values with annotations (e.g., type hints).
Pass Statement (pass_stmt): A placeholder that does nothing; used for syntactic requirements.
Del Statement (del_stmt): Deletes variables, items, or attributes.
Return Statement (return_stmt): Exits a function and optionally returns a value.
Yield Statement (yield_stmt): Produces a value from a generator function.
Raise Statement (raise_stmt): Raises exceptions for error handling.
Break Statement (break_stmt): Exits the closest enclosing loop.
Continue Statement (continue_stmt): Skips the current iteration of the closest enclosing loop.
Import Statement (import_stmt): Imports modules or specific components from modules.
Future Statement (future_stmt): Enables features from future versions of Python.
Global Statement (global_stmt): Declares variables as global within a function.
Nonlocal Statement (nonlocal_stmt): Declares variables as non-local, affecting scope in nested functions.
Type Statement (type_stmt): Declares or checks types (e.g., type hints).
Each simple statement performs a specific task and contributes to the overall functionality of the AVAP program.

Expression Statements
Expression statements are used (mostly interactively) to compute and write a value, or (usually) to call a method (a function that does not return a meaningful result; in Python, methods return the value None). Other uses of expression statements are allowed and occasionally useful. The syntax for an expression statement is:

expression_stmt ::=  starred_expression
An expression statement evaluates the list of expressions (which can be a single expression).

In interactive mode, if the value is not None, it is converted to a string using the built-in function repr(), and the resulting string is written to the standard output on a line by itself (except if the result is None, in which case the called procedure produces no output).

Assignment Statements
Assignment statements in AVAP are used to (re)assign names to values and to modify attributes or elements of mutable objects. Here is the syntax:

assignment_stmt ::=  (target_list "=")+ (starred_expression | yield_expression) target_list     ::=  target ("," target)* [","] target          ::=  identifier | "(" [target_list] ")" | "[" [target_list] "]" | attributeref | subscription | slicing | "*" target
Here's a breakdown of how assignment statements work:

Assignment Operation: An assignment statement evaluates the list of expressions and assigns the single resulting object to each of the target lists, from left to right.
Recursive Definition: The assignment operation is defined recursively depending on the form of the target list.
Target List: If the target list is a single object without ending in a comma, the object is assigned to that target. If the list contains a target prefixed with an asterisk, the object must be iterable with at least as many elements as targets, minus one. Elements before the starred target are assigned to the respective targets, and the remaining elements are assigned to the starred target.
Single Target: If the target is an identifier (name), it is bound to the object in the current local namespace. For other targets, names are bound in the global or enclosing namespace, depending on `nonlocal`.
Attribute Reference: If the target is an attribute reference, the primary expression is evaluated. It must produce an object with assignable attributes.
Subscription: If the target is a subscription, the primary expression is evaluated to produce a mutable sequence or mapping object, which is then used to assign the value.
Slice: If the target is a slice, the primary expression is evaluated, and the sequence object is requested to replace the slice with the assigned sequence elements.
In summary, assignment statements in AVAP are crucial for assigning values to variables and modifying data structures effectively.

Return Statement
The return statement in AVAP is used to return the value of a desired variable from a function. Here is the syntax:

return(variable_to_return):
Here is an overview of how the return statement works:

Function Context: The return statement can only occur within a function definition, not inside a nested class definition.
Variable Evaluation: If a variable is provided, it is evaluated. If no variable is specified, None is used by default.
Function Exit: The return statement exits the current function call and returns the specified value.
Interaction with try-finally: When the return statement is executed within a try statement that has a finally clause, the finally clause is executed before the function exits.
Generator Functions: In generator functions, the return statement indicates the end of the generator. It causes a StopIteration exception to be raised, with the returned value (if any) used to construct the StopIteration exception and set as the StopIteration.value attribute.
The return statement is a fundamental part of functions and generators, allowing for the output of values and proper function termination.

Raise Statement
In AVAP, the raise statement is used to throw an exception. The syntax for the raise statement is as follows:

raise [expression ["from" expression]]
If no expressions are present, raise re-raises the currently handled exception, also known as the active exception. If there is no active exception, a RuntimeError is raised indicating that it is an error.

Otherwise, raise evaluates the first expression as the exception object. It must be a subclass or an instance of BaseException. If it is a class, the exception instance is obtained when needed by creating an instance of the class without arguments.

The type of the exception is the instance of the exception class, and the value is the instance itself.

The from clause is used for exception chaining: if provided, the second expression must be another class or instance of exception. If the second expression is an exception instance, it will be attached to the raised exception as the __cause__ attribute (which is modifiable). If the expression is an exception class, the class will be instantiated and the resulting exception instance will be attached to the raised exception as the __cause__ attribute. If the raised exception is not handled, both exceptions will be printed.

startLoop() try: print(1 / 0) except Exception as exc: raise RuntimeError("Something went wrong") from exc endLoop()
A mechanism works implicitly if a new exception is raised while an exception is already being handled. An exception may be handled by an except or finally clause, or a with statement. The previous exception is then attached as the new exception’s __context__ attribute:

startLoop() try: print(1 / 0) except: raise RuntimeError("Something went wrong") from None endLoop()
Exception chaining can be explicitly suppressed by specifying None in the from clause:

startLoop() try: print(1 / 0) except: raise RuntimeError("Something went wrong") from None endLoop()
Break Statement
In AVAP, the break statement is used to terminate the closest enclosing loop. The syntax for the break statement is as follows:

break()
When a break statement is encountered, it causes the loop to exit immediately, regardless of the loop's condition or any remaining iterations. This effectively transfers control to the statement following the loop.

The break statement is typically used within for or while loops to provide a way to exit the loop prematurely based on a certain condition.

addVar(_status, "OK") startLoop(idx, 0, 9) if(idx, 4, "==") idx = -1 break() end() endLoop() addResult(idx) addStatus("OK")
In this example, the loop will terminate when i equals 5, and "Loop ended" will be printed. The numbers 0 through 4 will be printed before the loop is exited.

Break Statement
The break statement in AVAP is used to terminate the closest enclosing loop. Here is an overview of its behavior:

Usage Context: The break statement can only occur within a for or while loop. It cannot be nested within a function or class definition inside that loop.
Loop Termination: It terminates the closest enclosing loop and skips the optional else clause if the loop has one.
Loop Control Target: If a for loop is terminated by break, the loop control target retains its current value.
Interaction with try-finally: When break is executed within a try statement with a finally clause, the finally clause is executed before actually exiting the loop.
The break statement is essential for controlling loop execution, allowing for early exit from loops and proper handling of loop cleanup.

Continue Statement
In AVAP, the continue statement is used to proceed with the next iteration of the closest enclosing loop. The syntax for the continue statement is as follows:

continue
The continue statement can only syntactically occur nested within a for or while loop, but not within a function or class definition inside that loop.

When continue is used within a loop that is also handling exceptions with a try statement containing a finally clause, the finally clause is executed before the next iteration of the loop begins.

for i in range(10): try: if i % 2 == 0: continue print(i) finally: print("In finally clause") print("Loop ended")
In this example, the continue statement will skip the current iteration when i is even, but before moving to the next iteration, the finally clause will print "In finally clause." For odd numbers, the loop will print the number and then "In finally clause." After the loop finishes, "Loop ended" will be printed.

Include Statement
In AVAP, the include statement is used to include an entire code file and define names in the local namespace. The syntax for the include statement is as follows:

include file.avap
The include statement in AVAP includes an entire code file and makes it available in the local namespace. No alias is assigned to the included file; the file is simply referred to by its name.

For example:

# In the 'module.avap' file example_variable = 10 # In the main file include module.avap addResult(example_variable) # Will print 10
In this example, the main file includess the module.avap file and can access the example_variable defined in that file using the module.avap syntax.

Compound Statements
In AVAP, compound statements contain (groups of) other statements; these affect or control the execution of those other statements in some way. In general, compound statements span multiple lines, though in simpler representations a complete compound statement might be contained within a single line.

if statements implement traditional flow control constructs. match specifies matching patterns for variable values. Function and class definitions are also syntactically compound statements.

A compound statement consists of one or more "clauses." A clause consists of a header and a "suite." The clause headers of a particular compound statement are all at the same level of indentation. Each clause header begins with a uniquely identifying keyword and ends with a colon. A suite is a group of statements controlled by a clause. A suite can be one or more simple statements separated by semicolons on the same line as the header, following the colon of the header, or it can be one or more statements indented on subsequent lines. Only the latter form of a suite can contain nested compound statements.

Control Flow Structures in AVAP
In AVAP, control flow structures include conditional statements and loops, which allow you to control the flow of execution based on conditions and iterate over a range of values.

If Statements
The syntax for an if statement in AVAP is:

if (variable, variableValue, comparator, expression) code to execute else() code to execute end()
This structure checks if the condition (variable compared to variableValue with the given comparator) is true, and if so, executes the block of code.

Loops
The syntax for a loop in AVAP is:

startLoop(variable, from, to) code to execute endLoop()
This structure initiates a loop where the variable iterates from the 'from' value to the 'to' value, executing the code block for each iteration.

The if Statement
The if statement in AVAP is used for conditional execution. The syntax is as follows:

if (variable, variableValue, comparator, expression) code to execute else() code to execute end()
This statement evaluates the condition specified by the variable, variableValue, comparator, and expression. It selects exactly one of the suites (blocks of code) by evaluating the expressions one by one until a true condition is found. The corresponding suite is then executed. If all conditions are false, no suites are executed.

The try Statement
The try statement in AVAP specifies exception handlers and/or cleanup code for a block of statements. The syntax is as follows:

try() code to execute exception() code to execute end()
The try block contains code that might raise an exception. The exception block contains code to handle exceptions raised by the try block. If an exception occurs, control is transferred to the except block. If no exception occurs, the except block is skipped.

Additional information about exceptions can be found in the section Exceptions, and information about using the raise statement to throw exceptions can be found in the section The raise Statement.