diff options
author | Chenbo Li <lichenbo1949@gmail.com> | 2013-08-02 23:44:26 +0800 |
---|---|---|
committer | Chenbo Li <lichenbo1949@gmail.com> | 2013-08-02 23:44:26 +0800 |
commit | 90fa867a66323c9936b9b6f833f1c6b9eb7a16ad (patch) | |
tree | d236da21d945b9d6f9370b2d770aad19d59280ca | |
parent | 1a52aefcba5c31bb05b58290380509d6da81045c (diff) | |
parent | 3baf491ea66ddc77fb949c7aa5e988c318e372c0 (diff) |
Merge branch 'master' of https://github.com/adambard/learnxinyminutes-docs into master-cn
-rw-r--r-- | Visual Basic | 248 | ||||
-rw-r--r-- | c.html.markdown | 2 | ||||
-rw-r--r-- | coffeescript.html.markdown | 55 | ||||
-rw-r--r-- | php.html.markdown | 17 | ||||
-rw-r--r-- | ruby.html.markdown | 13 | ||||
-rw-r--r-- | visualbasic.html.markdown | 281 | ||||
-rw-r--r-- | whip.html.markdown | 238 | ||||
-rwxr-xr-x | zh-cn/c-cn.html.markdown | 5 | ||||
-rwxr-xr-x | zh-cn/elisp-cn.html.markdown | 10 | ||||
-rwxr-xr-x | zh-cn/java-cn.html.markdown | 9 | ||||
-rwxr-xr-x | zh-cn/javascript-cn.html.markdown | 11 | ||||
-rwxr-xr-x | zh-cn/php-cn.html.markdown | 3 |
12 files changed, 877 insertions, 15 deletions
diff --git a/Visual Basic b/Visual Basic new file mode 100644 index 00000000..73430633 --- /dev/null +++ b/Visual Basic @@ -0,0 +1,248 @@ +--- +language: Visual Basic Console Application +contributors: + - ["Brian Martin", "http://brianmartin.biz"] +filename: learnvisualbasic.vb + +Module Module1 + + Sub Main() + 'A Quick Overview of Visual Basic Console Applications before we dive in to the deep end. + 'Apostrophe starts comments. + 'To Navigate this tutorial within the Visual Basic Complier, I've put together a navigation system. + 'This navigation system is explained however as we go deeper into this tutorial, you'll understand what it all means. + Console.Title = ("Learn X in Y Minutes") + Console.WriteLine("NAVIGATION") 'Display + Console.WriteLine("") + Console.ForegroundColor = ConsoleColor.Green + Console.WriteLine("1. Hello World Output") + Console.WriteLine("2. Hello World Input") + Console.WriteLine("3. Calculating Whole Numbers") + Console.WriteLine("4. Calculating Decimal Numbers") + Console.WriteLine("5. Working Calculator") + Console.WriteLine("6. Using Do While Loops") + Console.WriteLine("7. Using For While Loops") + Console.WriteLine("8. Conditional Statements") + Console.WriteLine("9. Select A Drink") + Console.WriteLine("50. About") + Console.WriteLine("Please Choose A Number From The Above List") + Dim selection As String = Console.ReadLine + Select Case selection + Case "1" 'HelloWorld Output + Console.Clear() 'Clears the application and opens the private sub + HelloWorldOutput() 'Name Private Sub, Opens Private Sub + Case "2" 'Hello Input + Console.Clear() + HelloWorldInput() + Case "3" 'Calculating Whole Numbers + Console.Clear() + CalculatingWholeNumbers() + Case "4" 'Calculting Decimal Numbers + Console.Clear() + CalculatingDecimalNumbers() + Case "5" 'Working Calcculator + Console.Clear() + WorkingCalculator() + Case "6" 'Using Do While Loops + Console.Clear() + UsingDoWhileLoops() + Case "7" 'Using For While Loops + Console.Clear() + UsingForLoops() + Case "8" 'Conditional Statements + Console.Clear() + ConditionalStatement() + Case "9" 'If/Else Statement + Console.Clear() + IfElseStatement() 'Select a drink + Case "50" 'About msg box + Console.Clear() + Console.Title = ("Learn X in Y Minutes :: About") + MsgBox("Learn X in Y Minutes is a creation of Adam Bard (@adambard) This particular program tutorial is by Brian Martin (@BrianMartinn") + Console.Clear() + Main() + Console.ReadLine() + + End Select + End Sub + + 'One - I'm using numbers to help with the above navigation when I come back later to build it. + Private Sub HelloWorldOutput() 'We use private subs to seperate different sections of the program. + Console.Title = "Hello World Ouput | Learn X in Y Minutes" 'Title of Console Application + 'Use Console.Write("") or Console.WriteLine("") to print outputs. + 'Followed by Console.Read() alternatively Console.Readline() + 'Console.ReadLine() prints the output to the console. + Console.WriteLine("Hello World") + Console.ReadLine() + End Sub + 'Two + Private Sub HelloWorldInput() 'We use private subs to seperate different sections of the program. + Console.Title = "Hello World YourName | Learn X in Y Minutes" 'Title of Console Application + 'Variables + 'Data entered by a user needs to be stored. + 'Variables also start with a Dim and end with an As VariableType. + Dim username As String 'In this tutorial, we want to know what your name, and make the program respond to what is said. + 'We use string as string is a text based variable. + Console.WriteLine("Hello, What is your name? ") 'Ask the user their name. + username = Console.ReadLine() 'Stores the users name. + Console.WriteLine("Hello " + username) 'Output is Hello 'Their name' + Console.ReadLine() 'Outsputs the above. + 'The above will ask you a question followed by printing your answer. + 'Other variables include Integer and we use Integer for whole numbers. + End Sub + 'Three + Private Sub CalculatingWholeNumbers() 'We use private subs to seperate different sections of the program. + Console.Title = "Calculating Whole Numbers | Learn X in Y Minutes" 'Title of Console Application + Console.Write("First number: ") 'Enter a whole number, 1, 2, 50, 104 ect + Dim a As Integer = Console.ReadLine() + Console.Write("Second number: ") 'Enter second whole number. + Dim b As Integer = Console.ReadLine() + Dim c As Integer = a + b + Console.WriteLine(c) + Console.ReadLine() + 'The above is a simple calculator + End Sub + 'Four + Private Sub CalculatingDecimalNumbers() + Console.Title = "Calculating with Double | Learn X in Y Minutes" 'Title of Console Application + 'Of course we would like to be able to add up decimals. + 'Therefore we could change the above from Integer to Double. + Console.Write("First number: ") 'Enter a whole number, 1.2, 2.4, 50.1, 104.9 ect + Dim a As Double = Console.ReadLine + Console.Write("Second number: ") 'Enter second whole number. + Dim b As Double = Console.ReadLine + Dim c As Double = a + b + Console.WriteLine(c) + Console.ReadLine() + 'Therefore the above program can add up 1.1 - 2.2 + End Sub + 'Five + Private Sub WorkingCalculator() + Console.Title = "The Working Calculator| Learn X in Y Minutes" 'Title of Console Application + 'However if you'd like the calculator to subtract, divide, multiple and add up. + 'Copy and paste the above again. + Console.Write("First number: ") 'Enter a whole number, 1.2, 2.4, 50.1, 104.9 ect + Dim a As Double = Console.ReadLine + Console.Write("Second number: ") 'Enter second whole number. + Dim b As Integer = Console.ReadLine + Dim c As Integer = a + b + Dim d As Integer = a * b + Dim e As Integer = a - b + Dim f As Integer = a / b + 'By adding the below lines we are able to calculate the subtract, multply as well as divide the a and b values + Console.Write(a.ToString() + " + " + b.ToString()) + Console.WriteLine(" = " + c.ToString.PadLeft(3)) 'We want to pad the answers to the left by 3 spaces. + Console.Write(a.ToString() + " * " + b.ToString()) + Console.WriteLine(" = " + d.ToString.PadLeft(3)) 'We want to pad the answers to the left by 3 spaces. + Console.Write(a.ToString() + " - " + b.ToString()) + Console.WriteLine(" = " + e.ToString.PadLeft(3)) 'We want to pad the answers to the left by 3 spaces. + Console.Write(a.ToString() + " / " + b.ToString()) + Console.WriteLine(" = " + e.ToString.PadLeft(3)) 'We want to pad the answers to the left by 3 spaces. + Console.ReadLine() + + End Sub + 'Six + Private Sub UsingDoWhileLoops() + 'Just as the previous private sub + 'This Time We Ask If The User Wishes To Continue (Yes or No?) + 'We're using Do While Loop as we're unsure if the user wants to use the program more than once. + Console.Title = "UsingDoWhileLoops | Learn X in Y Minutes" + Dim answer As String 'We use the variable "String" as the answer is text + Do 'We start the program with + Console.Write("First number: ") + Dim a As Double = Console.ReadLine + Console.Write("Second number: ") + Dim b As Integer = Console.ReadLine + Dim c As Integer = a + b + Dim d As Integer = a * b + Dim e As Integer = a - b + Dim f As Integer = a / b + + Console.Write(a.ToString() + " + " + b.ToString()) + Console.WriteLine(" = " + c.ToString.PadLeft(3)) + Console.Write(a.ToString() + " * " + b.ToString()) + Console.WriteLine(" = " + d.ToString.PadLeft(3)) + Console.Write(a.ToString() + " - " + b.ToString()) + Console.WriteLine(" = " + e.ToString.PadLeft(3)) + Console.Write(a.ToString() + " / " + b.ToString()) + Console.WriteLine(" = " + e.ToString.PadLeft(3)) + Console.ReadLine() + 'Ask the question, does the user wish to continue? Unfortunately it is case sensitive. + Console.Write("Would you like to continue? (yes / no)") + answer = Console.ReadLine 'The program grabs the variable and prints and starts again. + Loop While answer = "yes" 'The command for the variable to work would be in this case "yes" + + End Sub + 'Seven + Private Sub UsingForLoops() + 'Sometimes the program only needs to run once. + 'In this program we'll be counting down from 10. + + Console.Title = "Using For Loops | Learn X in Y Minutes" + For i As Integer = 10 To 0 Step -1 'Declare Vairable and what number it should count down in Step -1, Step -2, Step -3 ect. + Console.WriteLine(i.ToString) 'Print the value of the counter variable + Next i 'Calculate new value + Console.WriteLine("Start") 'Lets start the program baby!! + Console.ReadLine() 'POW!! - Perhaps I got a little excited then :) + End Sub + 'Eight + Private Sub ConditionalStatement() + Console.Title = "Conditional Statements | Learn X in Y Minutes" + Dim userName As String = Console.ReadLine + Console.WriteLine("Hello, What is your name? ") 'Ask the user their name. + userName = Console.ReadLine() 'Stores the users name. + If userName = "Adam" Then 'Hey, if Adam uses this program, kudos where kudos is due, right? + Console.WriteLine("Hello Adam") + Console.WriteLine("Thanks for creating the useful tutorial site www.learnxinyminutes.com!") + Console.ReadLine() + Else + Console.WriteLine("Hello " + userName) 'prints the username of the user + Console.WriteLine("Hope all is well have you checked out www.learnxinyminutes.com") 'Prints a message to the user + Console.ReadLine() 'Ends and prints the above statement. + End If + End Sub + 'Nine + Private Sub IfElseStatement() + Console.Title = "If / Else Statement | Learn X in Y Minutes" + 'Sometimes its important to consider more than two alternatives. Sometimes there are a good few others. + 'When this is the case, more than one if statement would be required. + 'An if statement is great for vending machines. Where the user enters a code. + 'A1, A2, A3, ect to select an item. + 'All choices can be combined into a single if statement. + + Dim selection As String = Console.ReadLine 'Value for selection + Console.WriteLine("A1. for 7Up") + Console.WriteLine("A2. for Fanta") + Console.WriteLine("A3. for Dr. Pepper") + Console.WriteLine("A4. for Diet Coke") + Console.ReadLine() + If selection = "A1" Then + Console.WriteLine("7up") + Console.ReadLine() + ElseIf selection = "A2" Then + Console.WriteLine("fanta") + Console.ReadLine() + ElseIf selection = "A3" Then + Console.WriteLine("dr. pepper") + Console.ReadLine() + ElseIf selection = "A4" Then + Console.WriteLine("diet coke") + Console.ReadLine() + Else + Console.WriteLine("Please select a product") + Console.ReadLine() + End If + + End Sub + +End Module + + +``` +## References + +I learnt Visual Basic in the console application. It allowed me to understand the principles of computer programming to go on to learn other programming languages easily. + +I created a more indepth <a href="http://www.vbbootcamp.co.uk/" Title="Visual Basic Tutorial">Visual Basic tutorial</a> for those who would like to learn more. + +The entire syntax is valid. Copy the and paste in to the Visual Basic complier and run (F5) the program. diff --git a/c.html.markdown b/c.html.markdown index 132f75dc..b5286f70 100644 --- a/c.html.markdown +++ b/c.html.markdown @@ -1,4 +1,6 @@ --- +name: c +category: language language: c filename: learnc.c contributors: diff --git a/coffeescript.html.markdown b/coffeescript.html.markdown new file mode 100644 index 00000000..429f10b5 --- /dev/null +++ b/coffeescript.html.markdown @@ -0,0 +1,55 @@ +--- +language: coffeescript +contributors: + - ["Tenor Biel", "http://github.com/L8D"] +filename: coffeescript.coffee +--- + +``` coffeescript +# CoffeeScript is a hipster language. +# It goes with the trends of many modern languages. +# So comments are like Ruby and Python, they use hashes. + +### +Block comments are like these, and they translate directly to '/ *'s and '* /'s +for the resulting JavaScript code. + +You should understand most of JavaScript semantices +before continuing. +### + +# Assignment: +number = 42 #=> var number = 42; +opposite = true #=> var opposite = true; + +# Conditions: +number = -42 if opposite #=> if(opposite) { number = -42; } + +# Functions: +square = (x) -> x * x #=> var square = function(x) { return x * x; } + +# Ranges: +list = [1..5] #=> var list = [1, 2, 3, 4, 5]; + +# Objects: +math = + root: Math.sqrt + square: square + cube: (x) -> x * square x +#=> var math = { +# "root": Math.sqrt, +# "square": square, +# "cube": function(x) { return x * square(x); } +#} + +# Splats: +race = (winner, runners...) -> + print winner, runners + +# Existence: +alert "I knew it!" if elvis? +#=> if(typeof elvis !== "undefined" && elvis !== null) { alert("I knew it!"); } + +# Array comprehensions: +cubes = (math.cube num for num in list) #=> ... +``` diff --git a/php.html.markdown b/php.html.markdown index e81b88fd..5f5a4b54 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -9,7 +9,7 @@ filename: learnphp.php This document describes PHP 5+. ```php -<?php // PHP code must be enclosed with <?php ? > tags +<?php // PHP code must be enclosed with <?php ?> tags // If your php file only contains PHP code, it is best practise // to omit the php closing tag. @@ -101,6 +101,21 @@ echo 'This string ' . 'is concatenated'; /******************************** + * Constants + */ + +// A constant is defined by using define() +// and can never be changed during runtime! + +// a valid constant name starts with a letter or underscore, +// followed by any number of letters, numbers, or underscores. +define("FOO", "something"); + +// access to a constant is possible by direct using the choosen name +echo 'This outputs '.FOO; + + +/******************************** * Arrays */ diff --git a/ruby.html.markdown b/ruby.html.markdown index 38d060a3..a3bcbbd5 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -4,6 +4,7 @@ filename: learnruby.rb contributors: - ["David Underwood", "http://theflyingdeveloper.com"] - ["Joel Walden", "http://joelwalden.net"] + - ["Luke Holder", "http://twitter.com/lukeholder"] --- ```ruby @@ -30,6 +31,11 @@ You shouldn't either 10 * 2 #=> 20 35 / 5 #=> 7 +# Arithmetic is just syntactic sugar +# for calling a method on an object +1.+(3) #=> 4 +10.* 5 #=> 50 + # Special values are objects nil # Nothing to see here true # truth @@ -121,6 +127,12 @@ array = [1, "hello", false] #=> => [1, "hello", false] array[0] #=> 1 array[12] #=> nil +# Like arithmetic, [var] access +# is just syntactic sugar +# for calling a method [] on an object +array.[] 0 #=> 1 +array.[] 12 #=> nil + # From the end array[-1] #=> 5 @@ -312,4 +324,5 @@ dwight.name #=> "Dwight K. Schrute" # Call the class method Human.say("Hi") #=> "Hi" + ``` diff --git a/visualbasic.html.markdown b/visualbasic.html.markdown new file mode 100644 index 00000000..fbfa500d --- /dev/null +++ b/visualbasic.html.markdown @@ -0,0 +1,281 @@ +--- +language: Visual Basic +contributors: + - ["Brian Martin", "http://brianmartin.biz"] +filename: learnvisualbasic.vb +--- + +```vb +Module Module1 + + Sub Main() + ' A Quick Overview of Visual Basic Console Applications before we dive + ' in to the deep end. + ' Apostrophe starts comments. + ' To Navigate this tutorial within the Visual Basic Complier, I've put + ' together a navigation system. + ' This navigation system is explained however as we go deeper into this + ' tutorial, you'll understand what it all means. + Console.Title = ("Learn X in Y Minutes") + Console.WriteLine("NAVIGATION") 'Display + Console.WriteLine("") + Console.ForegroundColor = ConsoleColor.Green + Console.WriteLine("1. Hello World Output") + Console.WriteLine("2. Hello World Input") + Console.WriteLine("3. Calculating Whole Numbers") + Console.WriteLine("4. Calculating Decimal Numbers") + Console.WriteLine("5. Working Calculator") + Console.WriteLine("6. Using Do While Loops") + Console.WriteLine("7. Using For While Loops") + Console.WriteLine("8. Conditional Statements") + Console.WriteLine("9. Select A Drink") + Console.WriteLine("50. About") + Console.WriteLine("Please Choose A Number From The Above List") + Dim selection As String = Console.ReadLine + Select Case selection + Case "1" 'HelloWorld Output + Console.Clear() 'Clears the application and opens the private sub + HelloWorldOutput() 'Name Private Sub, Opens Private Sub + Case "2" 'Hello Input + Console.Clear() + HelloWorldInput() + Case "3" 'Calculating Whole Numbers + Console.Clear() + CalculatingWholeNumbers() + Case "4" 'Calculting Decimal Numbers + Console.Clear() + CalculatingDecimalNumbers() + Case "5" 'Working Calcculator + Console.Clear() + WorkingCalculator() + Case "6" 'Using Do While Loops + Console.Clear() + UsingDoWhileLoops() + Case "7" 'Using For While Loops + Console.Clear() + UsingForLoops() + Case "8" 'Conditional Statements + Console.Clear() + ConditionalStatement() + Case "9" 'If/Else Statement + Console.Clear() + IfElseStatement() 'Select a drink + Case "50" 'About msg box + Console.Clear() + Console.Title = ("Learn X in Y Minutes :: About") + MsgBox("This tutorial is by Brian Martin (@BrianMartinn") + Console.Clear() + Main() + Console.ReadLine() + + End Select + End Sub + + 'One - I'm using numbers to help with the above navigation when I come back + 'later to build it. + + 'We use private subs to seperate different sections of the program. + Private Sub HelloWorldOutput() + 'Title of Console Application + Console.Title = "Hello World Ouput | Learn X in Y Minutes" + 'Use Console.Write("") or Console.WriteLine("") to print outputs. + 'Followed by Console.Read() alternatively Console.Readline() + 'Console.ReadLine() prints the output to the console. + Console.WriteLine("Hello World") + Console.ReadLine() + End Sub + + 'Two + Private Sub HelloWorldInput() + Console.Title = "Hello World YourName | Learn X in Y Minutes" + ' Variables + ' Data entered by a user needs to be stored. + ' Variables also start with a Dim and end with an As VariableType. + + ' In this tutorial, we want to know what your name, and make the program + ' respond to what is said. + Dim username As String + 'We use string as string is a text based variable. + Console.WriteLine("Hello, What is your name? ") 'Ask the user their name. + username = Console.ReadLine() 'Stores the users name. + Console.WriteLine("Hello " + username) 'Output is Hello 'Their name' + Console.ReadLine() 'Outsputs the above. + 'The above will ask you a question followed by printing your answer. + 'Other variables include Integer and we use Integer for whole numbers. + End Sub + + 'Three + Private Sub CalculatingWholeNumbers() + Console.Title = "Calculating Whole Numbers | Learn X in Y Minutes" + Console.Write("First number: ") 'Enter a whole number, 1, 2, 50, 104 ect + Dim a As Integer = Console.ReadLine() + Console.Write("Second number: ") 'Enter second whole number. + Dim b As Integer = Console.ReadLine() + Dim c As Integer = a + b + Console.WriteLine(c) + Console.ReadLine() + 'The above is a simple calculator + End Sub + + 'Four + Private Sub CalculatingDecimalNumbers() + Console.Title = "Calculating with Double | Learn X in Y Minutes" + 'Of course we would like to be able to add up decimals. + 'Therefore we could change the above from Integer to Double. + + 'Enter a whole number, 1.2, 2.4, 50.1, 104.9 ect + Console.Write("First number: ") + Dim a As Double = Console.ReadLine + Console.Write("Second number: ") 'Enter second whole number. + Dim b As Double = Console.ReadLine + Dim c As Double = a + b + Console.WriteLine(c) + Console.ReadLine() + 'Therefore the above program can add up 1.1 - 2.2 + End Sub + + 'Five + Private Sub WorkingCalculator() + Console.Title = "The Working Calculator| Learn X in Y Minutes" + 'However if you'd like the calculator to subtract, divide, multiple and + 'add up. + 'Copy and paste the above again. + Console.Write("First number: ") + Dim a As Double = Console.ReadLine + Console.Write("Second number: ") 'Enter second whole number. + Dim b As Integer = Console.ReadLine + Dim c As Integer = a + b + Dim d As Integer = a * b + Dim e As Integer = a - b + Dim f As Integer = a / b + + 'By adding the below lines we are able to calculate the subtract, + 'multply as well as divide the a and b values + Console.Write(a.ToString() + " + " + b.ToString()) + 'We want to pad the answers to the left by 3 spaces. + Console.WriteLine(" = " + c.ToString.PadLeft(3)) + Console.Write(a.ToString() + " * " + b.ToString()) + Console.WriteLine(" = " + d.ToString.PadLeft(3)) + Console.Write(a.ToString() + " - " + b.ToString()) + Console.WriteLine(" = " + e.ToString.PadLeft(3)) + Console.Write(a.ToString() + " / " + b.ToString()) + Console.WriteLine(" = " + e.ToString.PadLeft(3)) + Console.ReadLine() + + End Sub + + 'Six + Private Sub UsingDoWhileLoops() + 'Just as the previous private sub + 'This Time We Ask If The User Wishes To Continue (Yes or No?) + 'We're using Do While Loop as we're unsure if the user wants to use the + 'program more than once. + Console.Title = "UsingDoWhileLoops | Learn X in Y Minutes" + Dim answer As String 'We use the variable "String" as the answer is text + Do 'We start the program with + Console.Write("First number: ") + Dim a As Double = Console.ReadLine + Console.Write("Second number: ") + Dim b As Integer = Console.ReadLine + Dim c As Integer = a + b + Dim d As Integer = a * b + Dim e As Integer = a - b + Dim f As Integer = a / b + + Console.Write(a.ToString() + " + " + b.ToString()) + Console.WriteLine(" = " + c.ToString.PadLeft(3)) + Console.Write(a.ToString() + " * " + b.ToString()) + Console.WriteLine(" = " + d.ToString.PadLeft(3)) + Console.Write(a.ToString() + " - " + b.ToString()) + Console.WriteLine(" = " + e.ToString.PadLeft(3)) + Console.Write(a.ToString() + " / " + b.ToString()) + Console.WriteLine(" = " + e.ToString.PadLeft(3)) + Console.ReadLine() + 'Ask the question, does the user wish to continue? Unfortunately it + 'is case sensitive. + Console.Write("Would you like to continue? (yes / no)") + 'The program grabs the variable and prints and starts again. + answer = Console.ReadLine + 'The command for the variable to work would be in this case "yes" + Loop While answer = "yes" + + End Sub + + 'Seven + Private Sub UsingForLoops() + 'Sometimes the program only needs to run once. + 'In this program we'll be counting down from 10. + + Console.Title = "Using For Loops | Learn X in Y Minutes" + 'Declare Variable and what number it should count down in Step -1, + 'Step -2, Step -3 ect. + For i As Integer = 10 To 0 Step -1 + Console.WriteLine(i.ToString) 'Print the value of the counter + Next i 'Calculate new value + Console.WriteLine("Start") 'Lets start the program baby!! + Console.ReadLine() 'POW!! - Perhaps I got a little excited then :) + End Sub + + 'Eight + Private Sub ConditionalStatement() + Console.Title = "Conditional Statements | Learn X in Y Minutes" + Dim userName As String = Console.ReadLine + Console.WriteLine("Hello, What is your name? ") 'Ask the user their name. + userName = Console.ReadLine() 'Stores the users name. + If userName = "Adam" Then + Console.WriteLine("Hello Adam") + Console.WriteLine("Thanks for creating this useful site") + Console.ReadLine() + Else + Console.WriteLine("Hello " + userName) + Console.WriteLine("Have you checked out www.learnxinyminutes.com") + Console.ReadLine() 'Ends and prints the above statement. + End If + End Sub + + 'Nine + Private Sub IfElseStatement() + Console.Title = "If / Else Statement | Learn X in Y Minutes" + 'Sometimes its important to consider more than two alternatives. + 'Sometimes there are a good few others. + 'When this is the case, more than one if statement would be required. + 'An if statement is great for vending machines. Where the user enters a code. + 'A1, A2, A3, ect to select an item. + 'All choices can be combined into a single if statement. + + Dim selection As String = Console.ReadLine 'Value for selection + Console.WriteLine("A1. for 7Up") + Console.WriteLine("A2. for Fanta") + Console.WriteLine("A3. for Dr. Pepper") + Console.WriteLine("A4. for Diet Coke") + Console.ReadLine() + If selection = "A1" Then + Console.WriteLine("7up") + Console.ReadLine() + ElseIf selection = "A2" Then + Console.WriteLine("fanta") + Console.ReadLine() + ElseIf selection = "A3" Then + Console.WriteLine("dr. pepper") + Console.ReadLine() + ElseIf selection = "A4" Then + Console.WriteLine("diet coke") + Console.ReadLine() + Else + Console.WriteLine("Please select a product") + Console.ReadLine() + End If + + End Sub + +End Module + +``` + +## References + +I learnt Visual Basic in the console application. It allowed me to understand the principles of computer programming to go on to learn other programming languages easily. + +I created a more indepth <a href="http://www.vbbootcamp.co.uk/" Title="Visual Basic Tutorial">Visual Basic tutorial</a> for those who would like to learn more. + +The entire syntax is valid. Copy the and paste in to the Visual Basic compiler and run (F5) the program. diff --git a/whip.html.markdown b/whip.html.markdown new file mode 100644 index 00000000..b8852ecb --- /dev/null +++ b/whip.html.markdown @@ -0,0 +1,238 @@ +--- +language: whip +contributors: + - ["Tenor Biel", "http://github.com/L8D"] +author: Tenor Biel +author_url: http://github.com/L8D +filename: whip.lisp +--- + +Whip is a LISP-dialect made for scripting and simplified concepts. +It has also borrowed a lot of functions and syntax from Haskell(a non-related language). + +These docs were written by the creator of the language himself. So is this line. + +```scheme +; Comments are like LISP. Semi-colons... + +; Majority of first-level statements are inside "forms" +; which are just things inside parens separated by whitespace +not_in_form +(in_form) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; 1. Numbers, Strings, and Operators + +; Whip has one number type (which is a 64-bit IEEE 754 double, from JavaScript). +3 ; => 3 +1.5 ; => 1.5 + +; Functions are called if they are the first element in a form +(called_function args) + +; Majority of operations are done with functions +; All the basic arihmetic is pretty straight forward +(+ 1 1) ; => 2 +(- 2 1) ; => 1 +(* 1 2) ; => 2 +(/ 2 1) ; => 2 +; even modulo +(% 9 4) ; => 1 +; JavaScript-style uneven division. +(/ 5 2) ; => 2.5 + +; Nesting forms works as you expect. +(* 2 (+ 1 3)) ; => 8 + +; There's a boolean type. +true +false + +; String are created with ". +"Hello, world" + +; Single chars are created with '. +'a' + +; Negation uses the 'not' function. +(not true) ; => false +(not false) ; => true + +; But the majority of non-haskell functions have shortcuts +; not's shortcut is a '!'. +(! (! true)) ; => true + +; Equality is `equal` or `=`. +(= 1 1) ; => true +(equal 2 1) ; => false + +; For example, inequality would be combinding the not and equal functions. +(! (= 2 1)) ; => true + +; More comparisons +(< 1 10) ; => true +(> 1 10) ; => false +; and their word counterpart. +(lesser 1 10) ; => true +(greater 1 10) ; => false + +; Strings can be concatenated with +. +(+ "Hello " "world!") ; => "Hello world!" + +; You can use JavaScript's comparative abilities. +(< 'a' 'b') ; => true +; ...and type coercion +(= '5' 5) + +; The `at` or @ function will access characters in strings, starting at 0. +(at 0 'a') ; => 'a' +(@ 3 "foobar") ; => 'b' + +; There is also the `null` and `undefined` variables. +null ; used to indicate a deliberate non-value +undefined ; user to indicate a value that hasn't been set + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; 2. Vairbles, Lists, and Dicts + +; Variables are declared with the `def` or `let` functions. +; Variab;es that haven't been set will be `undefined`. +(def some_var 5) +; `def` will keep the variable in the global context. +; `let` will only have the variable inside it's context, and has a wierder syntax. +(let ((a_var 5)) (+ a_var 5)) ; => 10 +(+ a_var 5) ; = undefined + 5 => undefined + +; Lists are arrays of values of any type. +; They basically are just forms without functions at the beginning. +(1 2 3) ; => [1, 2, 3] (JavaScript syntax) + +; Dictionaries are Whip's equivalent to JavaScript 'objects' or Python 'dicts' +; or Ruby 'hashes': an unordered collection of key-value pairs. +{"key1":"value1" "key2":2 3:3} + +; Keys are just values, either identifier, number, or string. +(def my_dict {my_key:"my_value" "my other key":4}) +; But in Whip, dictionaries get parsed like: value, colon, value; +; with whitespace between each. So that means +{"key": "value" +"another key" +: 1234 +} +; is evaluated to the same as +{"key":"value" "another key":1234} + +; Dictionary definitions can be accessed used the `at` function +; (like strings and lists.) +(@ "my other key" my_dict) ; => 4 + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; 3. Logic and Control sequences + +; The `if` function is pretty simple, though different than most imperitave langs. +(if true "returned if first arg is true" "returned if first arg is false") +; => "returned if first arg is true" + +; And for the sake of ternary operator legacy +; `?` is if's unused shortcut. +(? false true false) ; => false + +; `both` is a logical 'and' statement, and `either` is a logical 'or'. +(both true true) ; => true +(both true false) ; => false +(either true false) ; => true +(either false false) ; => false +; And their shortcuts are +; & => both +; ^ => either +(& true true) ; => true +(^ false true) ; => true + +;;;;;;;;; +; Lambdas + +; Lambdas in Whip are declared with the `lambda` or `->` function. +; And functions are really just lambdas with names. +(def my_function (-> (x y) (+ (x y) 10))) +; | | | | +; | | | returned value(with scope containing argument vars) +; | | arguments +; | lambda declaration function +; | +; name of the to-be-decalred lambda + +(my_function 10 10) ; = (+ (+ 10 10) 10) => 30 + +; Obiously, all lambdas by definition are anonymous and +; technically always used anonymouesly. Redundancy. +((lambda (x) x) 10) ; => 10 + +;;;;;;;;;;;;;;;; +; Comprehensions + +; `range` or `..` generates a list of numbers for +; each number between it's two args. +(range 1 5) ; => (1 2 3 4 5) +(.. 0 2) ; => (0 1 2) + +; `map` applies it's first arg(which should be a lambda/function) +; to each item in the following arg(which should be a list) +(map (-> (x) (+ x 1)) (1 2 3)) ; => (2 3 4) + +; Reduce +(reduce + (.. 1 5)) +; equivalent to +((+ (+ (+ 1 2) 3) 4) 5) + +; Note: map and reduce don't have shortcuts + +; `slice` or `\` is just like JavaScript's .slice() +; But do note, it takes the list as the first argument, not the last. +(slice (.. 1 5) 2) ; => (3 4 5) +(\ (.. 0 100) -5) ; => (96 97 98 99 100) + +; `append` or `<<` is self expanatory +(append 4 (1 2 3)) ; => (1 2 3 4) +(<< "bar" ("foo")) ; => ("foo" "bar") + +; Length is self explanatory. +(length (1 2 3)) ; => 3 +(_ "foobar") ; => 6 + +;;;;;;;;;;;;;;; +; Haskell fluff + +; First item in list +(head (1 2 3)) ; => 1 +; List from second to last elements in list +(tail (1 2 3)) ; => (2 3) +; Last item in list +(last (1 2 3)) ; => 3 +; Reverse of `tail` +(init (1 2 3)) ; => (1 2) +; List from first to specified elements in list +(take 1 (1 2 3 4)) ; (1 2) +; Reverse of `take` +(drop 1 (1 2 3 4)) ; (3 4) +; Lowest value in list +(min (1 2 3 4)) ; 1 +; Highest value in list +(max (1 2 3 4)) ; 4 +; If value is in list or object +(elem 1 (1 2 3)) ; true +(elem "foo" {"foo":"bar"}) ; true +(elem "bar" {"foo":"bar"}) ; false +; Reverse list order +(reverse (1 2 3 4)) ; => (4 3 2 1) +; If value is even or odd +(even 1) ; => false +(odd 1) ; => true +; Split string into list of strings by whitespace +(words "foobar nachos cheese") ; => ("foobar" "nachos" "cheese") +; Join list of strings together. +(unwords ("foo" "bar")) ; => "foobar" +(pred 21) ; => 20 +(succ 20) ; => 21 +``` + +For more info, check out the [repo](http://github.com/L8D/whip) diff --git a/zh-cn/c-cn.html.markdown b/zh-cn/c-cn.html.markdown index ed55203c..f8a8e0bd 100755 --- a/zh-cn/c-cn.html.markdown +++ b/zh-cn/c-cn.html.markdown @@ -2,9 +2,10 @@ language: c filename: learnc.c contributors: - - ["Adam Bard", "http://adambard.com/"]
+ - ["Adam Bard", "http://adambard.com/"] translators: - - ["Chenbo Li", "http://binarythink.net/"] + - ["Chenbo Li", "http://binarythink.net/"] +lang: zh-cn --- C语言在今天仍然是高性能计算的主要选择。 diff --git a/zh-cn/elisp-cn.html.markdown b/zh-cn/elisp-cn.html.markdown index d9a8ce35..c3a2f927 100755 --- a/zh-cn/elisp-cn.html.markdown +++ b/zh-cn/elisp-cn.html.markdown @@ -3,12 +3,15 @@ language: elisp contributors:
- ["Bastien Guerry", "http://bzg.fr"]
translators:
- - ["Chenbo Li", "http://binarythink.net"]
+ - ["Chenbo Li", "http://binarythink.net"]
filename: learn-emacs-lisp.el
+lang: zh-cn
---
```scheme
-;; 15分钟学会Emacs Lisp (v0.2a) (作者:bzg,https://github.com/bzg 译者:lichenbo,http://douban.com/people/lichenbo)
+;; 15分钟学会Emacs Lisp (v0.2a)
+;;(作者:bzg,https://github.com/bzg
+;; 译者:lichenbo,http://douban.com/people/lichenbo)
;;
;; 请先阅读Peter Norvig的一篇好文:
;; http://norvig.com/21-days.html
@@ -301,7 +304,8 @@ filename: learn-emacs-lisp.el (list 'face 'bold)))
(other-window 1))
-;; 这个函数使用了 `re-search-forward': 和查找一个字符串不同,你用这个命令可以查找一个模式,即正则表达式
+;; 这个函数使用了 `re-search-forward':
+;; 和查找一个字符串不同,你用这个命令可以查找一个模式,即正则表达式
;; 正则表达式 "Bonjour \\(.+\\)!" 的意思是:
;; 字符串 "Bonjour ", 之后跟着
diff --git a/zh-cn/java-cn.html.markdown b/zh-cn/java-cn.html.markdown index 4db4e91e..b9ccf61a 100755 --- a/zh-cn/java-cn.html.markdown +++ b/zh-cn/java-cn.html.markdown @@ -1,12 +1,13 @@ --- - +name: java +category: language language: java +lang: zh-cn +filename: LearnJava.java contributors: - ["Jake Prather", "http://github.com/JakeHP"] translators: - - ["Chenbo Li", "http://binarythink.net"] -filename: LearnJava.java - + - ["Chenbo Li", "http://binarythink.net"] --- Java是一个通用的程序语言, 包含并发, 基于类的面向对象等特性 diff --git a/zh-cn/javascript-cn.html.markdown b/zh-cn/javascript-cn.html.markdown index dd04c8a5..3b5cfa94 100755 --- a/zh-cn/javascript-cn.html.markdown +++ b/zh-cn/javascript-cn.html.markdown @@ -1,9 +1,12 @@ --- language: javascript -author: Adam Brenecki -author_url: http://adam.brenecki.id.au -translator: Chenbo Li -translator_url: http://binarythink.net +category: language +name: javascript +contributors: + - ["Adam Brenecki", "http://adam.brenecki.id.au"] +translators: + - ["Chenbo Li", "http://binarythink.net"] +lang: zh-cn --- Javascript于1995年由网景公司的Brendan Eich发明。 diff --git a/zh-cn/php-cn.html.markdown b/zh-cn/php-cn.html.markdown index e3dfe419..3b242ce1 100755 --- a/zh-cn/php-cn.html.markdown +++ b/zh-cn/php-cn.html.markdown @@ -4,8 +4,9 @@ contributors: - ["Malcolm Fell", "http://emarref.net/"] - ["Trismegiste", "https://github.com/Trismegiste"] translators: - - ["Chenbo Li", "http://binarythink.net"] + - ["Chenbo Li", "http://binarythink.net"] filename: learnphp.php +lang: zh-cn --- 这份教程所使用的版本是 PHP 5+. |