Tutorial by Examples: c

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 ...
When assigning named methods to delegates, they will refer to the same underlying object if: They are the same instance method, on the same instance of a class They are the same static method on a class public class Greeter { public void WriteInstance() { Console.Write...
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...
One feature provided for free by case classes is an auto-generated equals method that checks the value equality of all individual member fields instead of just checking the reference equality of the objects. With ordinary classes: class Foo(val i: Int) val a = new Foo(3) val b = new Foo(3) prin...
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. ...
Closures in Python are created by function calls. Here, the call to makeInc creates a binding for x that is referenced inside the function inc. Each call to makeInc creates a new instance of this function, but each instance has a link to a different binding of x. def makeInc(x): def inc(y): ...
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:...
The dynamics of the Geometric Brownian Motion (GBM) are described by the following stochastic differential equation (SDE): I can use the exact solution to the SDE to generate paths that follow a GBM. Given daily parameters for a year-long simulation mu = 0.08/250; sigma = 0.25/sqrt(...
int getListOfFriends(size_t size, int friend_indexes[]) { size_t i = 0; for (; i < size; i++) { friend_indexes[i] = i; } } C99C11 /* Type "void" and VLAs ("int friend_indexes[static size]") require C99 at least. In C11 VLAs are optional. */ void getLis...
One of the things that can really boost your productivity while writing the code is effectively navigating the workspace. This also means making it comfortable for the moment. It's possible to achieve this by adjusting which areas of workspaces you see. The buttons on the top of the navigation and ...
/** * Enables output buffer streaming. Calling this function * immediately flushes the buffer to the client, and any * subsequent output will be sent directly to the client. */ function _stream() { ob_implicit_flush(true); ob_end_flush(); }
When in a loop, the loop variable (val) in the following example is a single variable that changes value as it goes over the loop. Therefore one must do the following to actually pass each val of values to the goroutine: for val := range values { go func(val interface{}) { fmt.Println...
<?php foreach ($collection as $item): do_something($item); endforeach; ?> <?php foreach ($collection as $item): ?> <p>Do something in HTML with <?php echo $item; ?></p> <?php endforeach; ?>
<?php switch ($condition): case $value: do_something(); break; default: do_something_else(); break; endswitch; ?> <?php switch ($condition): ?> <?php case $value: /* having whitespace before your cases will cause an error */ ?&g...
Creating the class to be the subject of the Mirror class Project { var title: String = "" var id: Int = 0 var platform: String = "" var version: Int = 0 var info: String? } Creating an instance that will actually be the subject of the mirror. Also he...
m := make(map[string][]int) Accessing a non-existent key will return a nil slice as a value. Since nil slices act like zero length slices when used with append or other built-in functions you do not normally need to check to see if a key exists: // m["key1"] == nil && len(m[&qu...

Page 90 of 826