Tutorial by Examples: c

print_r() - Outputting Arrays and Objects for debugging print_r will output a human readable format of an array or object. You may have a variable that is an array or object. Trying to output it with an echo will throw the error: Notice: Array to string conversion. You can instead use the print_r...
Variables can be incremented or decremented by 1 using the ++ and -- operators, respectively. When the ++ and -- operators follow variables, they are called post-increment and post-decrement respectively. int a = 10; a++; // a now equals 11 a--; // a now equals 10 again When the ++ and -- ope...
let number = 3 switch number { case 1: print("One!") case 2: print("Two!") case 3: print("Three!") default: print("Not One, Two or Three") } switch statements also work with data types other than integers. They work with any data t...
A single case in a switch statement can match on multiple values. let number = 3 switch number { case 1, 2: print("One or Two!") case 3: print("Three!") case 4, 5, 6: print("Four, Five or Six!") default: print("Not One, Two, Three, Four, F...
A single case in a switch statement can match a range of values. let number = 20 switch number { case 0: print("Zero") case 1..<10: print("Between One and Ten") case 10..<20: print("Between Ten and Twenty") case 20..<30: print("Be...
var x = true, y = false; AND This operator will return true if both of the expressions evaluate to true. This boolean operator will employ short-circuiting and will not evaluate y if x evaluates to false. x && y; This will return false, because y is false. OR This operator wil...
Python lists are zero-indexed, and act like arrays in other languages. lst = [1, 2, 3, 4] lst[0] # 1 lst[1] # 2 Attempting to access an index outside the bounds of the list will raise an IndexError. lst[4] # IndexError: list index out of range Negative indices are interpreted as countin...
dictionary = {"Hello": 1234, "World": 5678} print(dictionary["Hello"]) The above code will print 1234. The string "Hello" in this example is called a key. It is used to lookup a value in the dict by placing the key in square brackets. The number 1234 is ...
The exit construct can be used to pass a return code to the executing environment. #!/usr/bin/php if ($argv[1] === "bad") { exit(1); } else { exit(0); } By default an exit code of 0 will be returned if none is provided, i.e. exit is the same as exit(0). As exit is not a ...
The dict() constructor can be used to create dictionaries from keyword arguments, or from a single iterable of key-value pairs, or from a single dictionary and keyword arguments. dict(a=1, b=2, c=3) # {'a': 1, 'b': 2, 'c': 3} dict([('d', 4), ('e', 5), ('f', 6)]) # {'d': 4, 'e': ...
Operands of the abstract equality operator are compared after being converted to a common type. How this conversion happens is based on the specification of the operator: Specification for the == operator: 7.2.13 Abstract Equality Comparison The comparison x == y, where x and y are values, prod...
At the command line, first verify that you have Git installed: On all operating systems: git --version On UNIX-like operating systems: which git If nothing is returned, or the command is not recognized, you may have to install Git on your system by downloading and running the installer. See...
123.5.to_s #=> "123.5" String(123.5) #=> "123.5" Usually, String() will just call #to_s. Methods Kernel#sprintf and String#% behave similar to C: sprintf("%s", 123.5) #=> "123.5" "%s" % 123.5 #=> "123.5" "%d&quot...
"123.50".to_i #=> 123 Integer("123.50") #=> 123 A string will take the value of any integer at its start, but will not take integers from anywhere else: "123-foo".to_i # => 123 "foo-123".to_i # => 0 However, there is a difference when ...
"123.50".to_f #=> 123.5 Float("123.50") #=> 123.5 However, there is a difference when the string is not a valid Float: "something".to_f #=> 0.0 Float("something") # ArgumentError: invalid value for Float(): "something"
The git clone command is used to copy an existing Git repository from a server to the local machine. For example, to clone a GitHub project: cd <path where you'd like the clone to create a directory> git clone https://github.com/username/projectname.git To clone a BitBucket project: cd ...
In its most simple form, an if condition can be used like this: var i = 0; if (i < 1) { console.log("i is smaller than 1"); } The condition i < 1 is evaluated, and if it evaluates to true the block that follows is executed. If it evaluates to false, the block is skipped....
Consider a database with the following two tables. Employees table: IdFNameLNameDeptId1JamesSmith32JohnJohnson4 Departments table: IdName1Sales2Marketing3Finance4IT Simple select statement * is the wildcard character used to select all available columns in a table. When used as a substitute f...
The JSONSerialization class is built into Apple's Foundation framework. 2.2 Read JSON The JSONObjectWithData function takes NSData, and returns AnyObject. You can use as? to convert the result to your expected type. do { guard let jsonData = "[\"Hello\", \"JSON\"]&q...
An enum provides a set of related values: enum Direction { case up case down case left case right } enum Direction { case up, down, left, right } Enum values can be used by their fully-qualified name, but you can omit the type name when it can be inferred: let dir = Dire...

Page 18 of 826