Skip to content

Commit

Permalink
Rework statements doc, extend intro and variable declaration explenat…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
schmalzing committed Nov 20, 2024
1 parent 054ddfb commit c56c7ba
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
47 changes: 27 additions & 20 deletions docs/behavior/Statements.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
This page summarizes the available statements in MontiArc.
Note that the are not available everywhere (e.g. they are not allowed directly
in component bodies), but usually where behavior is defined.
<!-- (c) https://github.com/MontiCore/monticore -->

## Operational statements
Actions are defined by a list of statements that are instructions to be
executed in some sequence. A statement can include one or more expressions.

## Variable declarations
Declaration statements declare variable and constants, specifying their data
type, name, and initial value. Some examples are given in the following.

### Variable declarations
```java
DataType varName;
DataType varName = initValue;
DataType var1Name, varName2 = initVal, varName3;
int a = 42;
```
Variables are declared by first defining their type
and then creating a name for them.
Usually, one assigns an initial value to the variable, but this is optional.
Moreover, one can define multiple variables of the same type within the same
statement, separating them with commas.
The declaration statement above declares a variable named `a` of type `int`
and assigns it the value `42`.

### Expression statements
```java
String text = "Hello";
```

The declaration statement above declares a variable named `text` of type
`String` and assigns it the value `"Hello"`.

A variables data type may also be some object type.

```java
Person person = Person.Person();
```

The declaration statement above declares a variable named `person` of type
`Parson` and assigns the variable to a new object of type `Person`;

## Expression statements
```java
x = 14;
foo.callToAMethod();
Expand All @@ -41,12 +54,6 @@ else elseStatement;
```
but this is discouraged.

### Empty statement
```java
;
```
It is possible to use the semicolon as a statement to signify that nothing should be done as part of the statement.

## Control statements

### If-else
Expand Down
1 change: 0 additions & 1 deletion docs/behavior/Timing.md

This file was deleted.

0 comments on commit c56c7ba

Please sign in to comment.