Posts

Showing posts from November, 2021

5. Dart - Function Basics

Function Parameters: function(int variableint) {     print(variableint) } // lets functions use variables given when called. // can add more than one parameter, just separate them with commas. // can add a type (String, int, etc) prior to function name to specify it more. // optional paramenters are encased with square brackets. Adding Parameters to Function Calls:     function(5); Returning Variables from Function:      function(int variablenum) {           variable = variablenum + 2           return variable;      }     int test = 5;     x = function(test);     // returns the variable to where it was called. Return Example 2: String functionname() {     return "string" } // declares the return type in front of the function name Void:     void functionname() {          stuff here      }     // Indicates that the function does not and can not return anything, Single Line Functions: (when want to return a single value)     function(int test) => print(test);     void  functi

4. Dart - Try and On

 Try and do something else if failed function:     try {          variable = int.parse(variablestring);      } on FormatException {          do something else when cannot turn string to int      }

3. Dart - Built in Libraries 1

Importing Libaries:     import 'LIBRARYNAME'; RNG Library:     import 'dart:math'; Create a new RNG generator     Random variable = new Random(); RNG:     int variable = rand.nextInt(100);          // rolls from 0 to 99 for the variable Input Library:     import 'dart:io'; Create a variable to hold input:     String variable = stdin.readLineSync(); Converting String to int:     variable = int.parse(variablestring); Converting int to String:     variablestring = variableint.toString();

2. Dart - Logics

 Just like Golang. IF/THEN/ELSE/      if ( variable == 0 ) {          print("a");      } else if {          print("b");      } else {          print("c");      } Bool Types:     bool variable = true     if (variable) {          print("true");      }     this prints true because variable is true. Switch Cases:     Variable = "dance"     switch (variable) {          case ("dance"):               print("hello");               break;          case ("not dance"):               print("not hello");               break;          default:               print("default");      } While Loops:     while (variable == 0) {          do something      }     do {     } while (variable == 1);     another variation of while loop, but does the function first and check while later. For Loops:     for (int a = 5; a <10; a++) {      }     for loops lets declare set of rules. Basic Math Logic Signs:     ++ 

1. Dart - Basics

 Run Dart code in VSCODE with:     dart dartfile.dart Basic function format:     void  main() {           print("HELLO");      }     // OR exclude void. Void just mean function returns no values.      main() {           print("HELLO");      }      Calling Functions:     function(); Variables can have types:     int = int numbers.     double = float numbers.     String = strings.     bool = booleans.     List = like array. [1,2,3]     Map = like array. { "x":5, "y":6}     null = nothing     dynamic = a variable that can change its type Math Basics:     variable++          or               variable = variable + 1     variable--          or               variable = variable - 1 Referencing variables:     $variable          this references to the variable.     ${variable - 10}          adjusting the variable that is referenced. But doesnt change it. Escaping characters inside strings:     print("This is a semicolon \:");          use a back