Similar to the while loop, only the control statement is evaluated after the loop. Therefore, the loop will always execute at least once.
var i: Int = 0
repeat {
print(i)
i += 1
} while i < 3
// 0
// 1
// 2
A while loop will execute as long as the condition is true.
var count = 1
while count < 10 {
print("This is the \(count) run of the loop")
count += 1
}
Composer tracks which versions of packages you have installed in a file called composer.lock, which is intended to be committed to version control, so that when the project is cloned in the future, simply running composer install will download and install all the project's dependencies.
Composer de...
A lot of the power of ReactJS is its ability to allow nesting of components. Take the following two components:
var React = require('react');
var createReactClass = require('create-react-class');
var CommentList = reactCreateClass({
render: function() {
return (
<div className...
The operator for an "exclusive or" (for short XOR) is: ^
This operator returns true when one, but only one, of the supplied bools are true.
true ^ false // Returns true
false ^ true // Returns true
false ^ false // Returns false
true ^ true // Returns false
It is possible to bind values to names using @:
struct Badger {
pub age: u8
}
fn main() {
// Let's create a Badger instances
let badger_john = Badger { age: 8 };
// Now try to find out what John's favourite activity is, based on his age
match badger_john.age {
...
// Create a boolean value
let a = true;
// The following expression will try and find a pattern for our value starting with
// the topmost pattern.
// This is an exhaustive match expression because it checks for every possible value
match a {
true => println!("a is true"),
...
It's possible to treat multiple, distinct values the same way, using |:
enum Colour {
Red,
Green,
Blue,
Cyan,
Magenta,
Yellow,
Black
}
enum ColourModel {
RGB,
CMYK
}
// let's take an example colour
let colour = Colour::Red;
let model = match ...
Patterns can be matched based on values independent to the value being matched using if guards:
// Let's imagine a simplistic web app with the following pages:
enum Page {
Login,
Logout,
About,
Admin
}
// We are authenticated
let is_authenticated = true;
// But we aren't admins...
By default the Python random module use the Mersenne Twister PRNG to generate random numbers, which, although suitable in domains like simulations, fails to meet security requirements in more demanding environments.
In order to create a cryptographically secure pseudorandom number, one can use Syst...
index.html
<!doctype html>
<html>
<head>
<title>D3 Sample</title>
</head>
<body>
<!-- This will serve as a container for our chart. This does not have to be a div, and can in fact, just be the body if you want. -->
<div id=...
git shortlog summarizes git log and groups by author
If no parameters are given, a list of all commits made per committer will be shown in chronological order.
$ git shortlog
Committer 1 (<number_of_commits>):
Commit Message 1
Commit Message 2
...
Committer 2 (<number_of_...
The flow of execution of a Ruby block may be controlled with the break, next, and redo statements.
break
The break statement will exit the block immediately. Any remaining instructions in the block will be skipped, and the iteration will end:
actions = %w(run jump swim exit macarena)
index = 0
...
The following syntax creates a delegate type with name NumberInOutDelegate, representing a method which takes an int and returns an int.
public delegate int NumberInOutDelegate(int input);
This can be used as follows:
public static class Program
{
static void Main()
{
Number...
The System namespace contains Func<..., TResult> delegate types with between 0 and 15 generic parameters, returning type TResult.
private void UseFunc(Func<string> func)
{
string output = func(); // Func with a single generic type parameter returns that type
Console.WriteLine...
PHP will generally correctly guess the data type you intend to use from the context it's used in, however sometimes it is useful to manually force a type. This can be accomplished by prefixing the declaration with the name of the required type in parenthesis:
$bool = true;
var_dump($bool); // bool...
In Python 2, exec is a statement, with special syntax: exec code [in globals[, locals]]. In Python 3 exec is now a function: exec(code, [, globals[, locals]]), and the Python 2 syntax will raise a SyntaxError.
As print was changed from statement into a function, a __future__ import was also added. ...
On either Linux/UNIX or Windows, a script can be passed as an argument to the PHP executable, with that script's options and arguments following:
php ~/example.php foo bar
c:\php\php.exe c:\example.php foo bar
This passes foo and bar as arguments to example.php.
On Linux/UNIX, the preferred me...
The for keyword is also used for conditional loops, traditionally while loops in other programming languages.
package main
import (
"fmt"
)
func main() {
i := 0
for i < 3 { // Will repeat if condition is true
i++
fmt.Println(i)
}
}
play ...
In Python 2, when a property raise a error, hasattr will ignore this property, returning False.
class A(object):
@property
def get(self):
raise IOError
class B(object):
@property
def get(self):
return 'get in b'
a = A()
b = B()
print 'a hasattr get:...