Skip to content

Instantly share code, notes, and snippets.

@olaide-ekolere
Last active November 25, 2020 08:33
Show Gist options
  • Save olaide-ekolere/cfafad0c1b1b0a5f60793ec5d31d3f1e to your computer and use it in GitHub Desktop.
Save olaide-ekolere/cfafad0c1b1b0a5f60793ec5d31d3f1e to your computer and use it in GitHub Desktop.
Variables - Introduction to Dart
//This is a single line comment
/*
* This is a multiline comment
* and can span more than one
* line
*/
//Variables
/*
* Containers for holding values
*/
int age = 25;
int distance = 200;
var score = 78; //inferred
String name = "Olaide";
String fullname = "Olaide Nojeem Ekeolere";
var grade = "A"; //inferred
bool accepted = false;
bool failed = true;
var sleeping = true;//inferred
//Functions
/*
*/
void helloWorld() {
print("hello world!");
}
void main() {
helloWorld();
//print an outer variable
print(fullname);
//local variables
int cars = 5;
String city = "Lagos";
print(city);
print(cars);
//Operations
print(8 * 5);
print(cars + 4);
double result = 90 / 3;
print(result);
int division = 80 ~/ 4;
print(division);
int anotherScore = score + 10;
print(anotherScore);
//String concatination
print("hello " + "word");
print(name + " lives in " + city);
String anotherString = city + " is large";
print(anotherString);
print("$name scored $score");
//dynamic variable
dynamic superstar = "I am a String";
print(superstar);
superstar = 70;
print(" I am the integer $superstar");
superstar = false;
print("I am now a bool of $superstar");
//constant variables
const double pi = 3.14;
//pi = 4.56;
int radius = 70;
var perimeter = 2 * pi * radius;
print("Perimeter of circle with radius of $radius is $perimeter");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment