Tutorial by Examples

While loops and do while loops are allowed in Dart: while(peopleAreClapping()) { playSongs(); } and: do { processRequest(); } while(stillRunning()); Loops can be terminated using a break: while (true) { if (shutDownRequested()) break; processIncomingRequests(); } You can s...
Two types of for loops are allowed: for (int month = 1; month <= 12; month++) { print(month); } and: for (var object in flybyObjects) { print(object); } The for-in loop is convenient when simply iterating over an Iterable collection. There is also a forEach method that you can cal...
Dart has a switch case which can be used instead of long if-else statements: var command = 'OPEN'; switch (command) { case 'CLOSED': executeClosed(); break; case 'OPEN': executeOpen(); break; case 'APPROVED': executeApproved(); break; case 'UNSURE': ...
To check for a precise number of elements in the collection def f(ints: Seq[Int]): String = ints match { case Seq() => "The Seq is empty !" case Seq(first) => s"The seq has exactly one element : $first" case Seq(first, second) => s"The...
Prerequisites: NodeJS and npm There are two ways of installing Webpack: globally or per-project. It is best to have the dependency installed per-project, as this will allow you to use different versions of webpack for each project and don't require user to have installed webpack globally. Install...
All Java exceptions are instances of classes in the Exception class hierarchy. This can be represented as follows: java.lang.Throwable - This is the base class for all exception classes. Its methods and constructors implement a range of functionality common to all exceptions. java.lang.Excep...
$fruit1 = ['apples', 'pears']; $fruit2 = ['bananas', 'oranges']; $all_of_fruits = array_merge($fruit1, $fruit2); // now value of $all_of_fruits is [0 => 'apples', 1 => 'pears', 2 => 'bananas', 3 => 'oranges'] Note that array_merge will change numeric indexes, but overwrite string...
A function defined as async is a function that can perform asynchronous actions but still look synchronous. The way it's done is using the await keyword to defer the function while it waits for a Promise to resolve or reject. Note: Async functions are a Stage 4 ("Finished") proposal on tr...
A Pseudo Distributed Cluster Setup Procedure Prerequisites Install JDK1.7 and set JAVA_HOME environment variable. Create a new user as "hadoop". useradd hadoop Setup password-less SSH login to its own account su - hadoop ssh-keygen << Press ENTER for all prompt...
x = (1, 2, 3) x[0] # 1 x[1] # 2 x[2] # 3 x[3] # IndexError: tuple index out of range Indexing with negative numbers will start from the last element as -1: x[-1] # 3 x[-2] # 2 x[-3] # 1 x[-4] # IndexError: tuple index out of range Indexing a range of elements print(x[:-1]) # (1,...
A context manager is an object that is notified when a context (a block of code) starts and ends. You commonly use one with the with statement. It takes care of the notifying. For example, file objects are context managers. When a context ends, the file object is closed automatically: open_file = ...
In Python 2, an iterator can be traversed by using a method called next on the iterator itself: Python 2.x2.3 g = (i for i in range(0, 3)) g.next() # Yields 0 g.next() # Yields 1 g.next() # Yields 2 In Python 3 the .next method has been renamed to .__next__, acknowledging its “magic” ro...
SELECT * FROM Employees ORDER BY LName This statement will return all the columns from the table Employees. IdFNameLNamePhoneNumber2JohnJohnson24681012141JamesSmith12345678903MichaelWilliams1357911131 SELECT * FROM Employees ORDER BY LName DESC Or SELECT * FROM Employees ORDER BY LName ASC...
math modules includes two commonly used mathematical constants. math.pi - The mathematical constant pi math.e - The mathematical constant e (base of natural logarithm) >>> from math import pi, e >>> pi 3.141592653589793 >>> e 2.718281828459045 >>> P...
Windows Environment Install XAMPP or WAMP Download and Unzip the package from Codeigniter.com Extract all the document in the server space (htdocs or www directory) Mac Environment Install MAMP Download and Unzip the package from Codeigniter.com Extract all the document in the server sp...
If a name is bound inside a function, it is by default accessible only within the function: def foo(): a = 5 print(a) # ok print(a) # NameError: name 'a' is not defined Control flow constructs have no impact on the scope (with the exception of except), but accessing variable that w...
x and y are extracted from the tuple: val (x, y) = (1337, 42) // x: Int = 1337 // y: Int = 42 To ignore a value use _: val (_, y: Int) = (1337, 42) // y: Int = 42 To unpack an extractor: val myTuple = (1337, 42) myTuple._1 // res0: Int = 1337 myTuple._2 // res1: Int = 42 Note that...
A case class is a class with a lot of standard boilerplate code automatically included. One benefit of this is that Scala makes it easy to use extractors with case classes. case class Person(name: String, age: Int) // Define the case class val p = Person("Paola", 42) // Instantiate a v...
Many context managers return an object when entered. You can assign that object to a new name in the with statement. For example, using a database connection in a with statement could give you a cursor object: with database_connection as cursor: cursor.execute(sql_query) File objects retur...
The null coalescing operator makes it easy to ensure that a method that may return null will fall back to a default value. Without the null coalescing operator: string name = GetName(); if (name == null) name = "Unknown!"; With the null coalescing operator: string name = GetN...

Page 115 of 1336