Funksjoner

//eksempel på funksjon
//hvordan kan den forbedres? 
legg_sammen(i, j, k, l, m, n, o, p, q) {
var sum;
sum = i + j + k + l + m + n +o + p + q;
print (sum);
}

main() {
  //funksjonen "legg_sammen" legger sammen tallene i parentesen og skriver ut summen 
  legg_sammen(11,22,33,44,55,66,77,88,99);
  //reklame
  print('Give try.dartlang.org a try.');
}

http://blog.sethladd.com/2011/12/learning-functions-for-dart.html

Hilsen

class skriv {
  var hilse_tekst = 'Hei på deg,';

  helsing_til(navn) {
    print('$hilse_tekst $navn');
  }
}

main() {
  var skriv = new skriv();

  skriv.helsing_til("Kjell!");
}

-----
class Greeter {
  var prefix = 'Hello,';

  greet(name) {
    print('$prefix $name');
  }
}

main() {
  var greeter = new Greeter();
  greeter.greet("Class!");
} 

------

About the code

The preceding code shows some basic features of Dart classes:

class statement
This example defines a class, named Greeter, that has the default superclass: Object. In Dart, all classes descend from Object, either directly or indirectly. Use the extends keyword if you want to specify a non-Object superclass.
Instance variable
Just as for regular variables, creating instance variables requires using var, final, or a type. Each Greeter object has its own copy of a variable named prefix that’s initialized to 'Hello,'.You can set instance variables directly (for example, greeter.prefix = 'Hi,'), or through constructors, or through setter methods. (Setter and getter methods are discussed in the “More about classes” section, below.)
Constructor
You can create instances of a class by invoking new followed by a constructor for the class—in this case, new Greeter(). Because this code doesn’t define any Greeter constructors, it gets a default version that calls the superclass’s no-argument constructor. The superclass of Greeter is Object, so the code new Greeter() invokes the Object() constructor.
Instance method
The greet() method defines a function that’s tied to a Greeter object.
No specified types
Specifying types is optional in Dart. Types can help you write and maintain your code, but they don’t change how Dart programs behave.

More about classes

Classes in Dart have many additional features. Two of the most commonly used ones are named constructors and setters and getters.

Named constructors
If you need more than one constructor for a class, then you can define named constructors—for example, Greeter.withPrefix(). When you define a constructor, the default no-argument constructor won’t be created for you; you’ll need to add it if you want it. For example:

// In the Greeter class:
Greeter();
Greeter.withPrefix(this.prefix);

// In code that creates Greeter objects:
var greeter = new Greeter.withPrefix('Howdy,');

In that code, this.prefix is a shortcut that assigns the parameter’s value to the instance variable prefix.

Setters and getters
Setters and getters are a way of providing access to data without directly exposing instance variables. Here’s an example of providing a setter and getter for the prefix data in the Greeterclass:

class Greeter {
  String _prefix = 'Hello,';          // Hidden instance variable.

  String get prefix() => _prefix;     // Getter for prefix.

  void set prefix(String value) {     // Setter for prefix.
    if (value == null) value = "";
    if (value.length > 20) throw 'Prefix too long!';
    _prefix = value;
  }

  greet(name) {
    print('$prefix $name');
  }
}

main() {
  var greeter = new Greeter();
  greeter.prefix = 'Howdy,';         // Set prefix.
  greeter.greet('setter!');
}
Note the special => syntax for prefix(). This shorthand notation makes the method return the value of the expression immediately following the => .

Try this

Set the value of the prefix instance variable.
For example, add this after line 10:

greeter.prefix = 'Hola,';
Add a named constructor to Greeter, and call it.
For example:

// In the Greeter class:
Greeter.withPrefix(this.prefix);

// In code that creates Greeter objects:
var greeter = new Greeter.withPrefix('Howdy,');
Add one or more types to the example.
Here’s what the example might look like if you add some types:

class Greeter {
  String prefix = 'Hello,';

  greet(String name) {
    print('$prefix $name');
  }
}

void main() {
  Greeter greeter = new Greeter();
  greeter.greet('types');
}

The golden ratio

// Ok, your turn!
main() {
var i,m;
i = 1;
m = 1;
while (i < 100){
  print (i);
  print (m);
  print (m/i);
  i = i + m;
  m = i + m;
  }

  print('Det var det');