# Code examples

## PrintUf

*printuf* prints a string and adds a little "uf" at the beginning:

```csharp
printuf("Hello World!");

// Output: "uf Hello World!"
```

## [Variables](/glados-uflang/features/types.md)

```csharp
var x : Int = 43;
var y : String = "hello";
var z : Double = 2.5;

print("Here is x: ");
println(x);
print("Here is y: ");
println(y);
print("Here is z: ");
println(z);

y = "hihi";
print("Here is y after set: ");
println(y);
```

```
output :
Here is x: 43
Here is y: hello
Here is z: 2.5
Here is y after set: hihi
```

```csharp
var variable = 23; // int created

variable = "now this is a text"; // becomes a string
```

## Classes

```csharp
class Foo {
  inFoo() {
    println "in foo";
  }
}

class Bar : Foo {
  inBar() {
    println "in bar";
  }
}

class Baz : Bar {
  inBaz() {
    println "in baz";
  }
}

var baz = Baz();
baz.inFoo(); // expect: in foo
baz.inBar(); // expect: in bar
baz.inBaz(); // expect: in baz
```

## Return types

```csharp
fun test(n)
{
    if (n == 1) {
        return "uf"; // string returned
    }
    if (n == 2) {
        return 23; // int returned
    }
    else {
        return 92.0; // double returned
    }
}

println test(1);
println test(2);
println test(3);
```

```
output:
uf
23
92
```

## Loops

```csharp
// Single-expression body.
/*
for (var c = 0; c < 3;) {
    println c = c + 1;
}
*/
// expect: 1
// expect: 2
// expect: 3

println "before for";
for (var c = 0; c < 3; c++) {
    println c;
}
println "after for";



// Block body.
for (var a = 0; a < 3; a = a + 1) {
  println a;
}
// expect: 0
// expect: 1
// expect: 2

// No clauses.

// No variable.
var i = 0;
for (; i < 2; i = i + 1) println i;
// expect: 0
// expect: 1

// No condition.
fun bar() {
  for (var i = 0;; i = i + 1) {
    println i;
    if (i >= 2) return;
  }
}
bar();
// expect: 0
// expect: 1
// expect: 2

// No increment.
for (var i = 0; i < 2;) {
  println i;
  i = i + 1;
}
// expect: 0
// expect: 1

// Statement bodies.
for (; false;) if (true) 1; else 2;
for (; false;) while (true) 1;
for (; false;) for (;;) 1;
```

```csharp
// Single-expression body.
var c = 0;
while (c < 3) println c = c + 1;
// expect: 1
// expect: 2
// expect: 3


// Block body.
var a = 0;
while (a < 3) {
  println a;
  a = a + 1;
}
// expect: 0
// expect: 1
// expect: 2


// Statement bodies.
while (false) if (true) 1; else 2;
while (false) while (true) 1;
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://glados-6.gitbook.io/glados-uflang/introduction/code-examples.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
