switch
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| switch [2017/06/27 16:03] – [switch Statement] gg | switch [2017/06/28 13:37] (current) – gg | ||
|---|---|---|---|
| Line 10: | Line 10: | ||
| ===== Bash ===== | ===== Bash ===== | ||
| + | |||
| + | === Das Programm === | ||
| <code bash> | <code bash> | ||
| #!/bin/bash | #!/bin/bash | ||
| Line 24: | Line 26: | ||
| *) echo "Ich kann nicht feststellen wie alt du bist. Bitte eine Zahl von 1-4 eingeben" | *) echo "Ich kann nicht feststellen wie alt du bist. Bitte eine Zahl von 1-4 eingeben" | ||
| esac | esac | ||
| + | </ | ||
| + | |||
| + | === Ausführen === | ||
| + | switch.sh erstellen und so ausführen | ||
| + | <code bash> | ||
| + | chmod +x switch.sh # als ausführbar markieren | ||
| + | ./ | ||
| </ | </ | ||
| ===== C++ ===== | ===== C++ ===== | ||
| + | === Das Programm === | ||
| <code cpp> | <code cpp> | ||
| #include < | #include < | ||
| Line 45: | Line 55: | ||
| } | } | ||
| </ | </ | ||
| + | === Kompilieren und ausführen === | ||
| + | switch.cpp erstellen und so kompilieren/ | ||
| + | <code bash> | ||
| + | g++ -Wall -g -std=c++14 switch.cpp -o switch # kompilieren | ||
| + | ./ | ||
| + | </ | ||
| ===== C# ===== | ===== C# ===== | ||
| + | === Das Programm === | ||
| <code csharp> | <code csharp> | ||
| using System; | using System; | ||
| Line 73: | Line 89: | ||
| ===== Golang ===== | ===== Golang ===== | ||
| + | === Das Programm === | ||
| <code go> | <code go> | ||
| + | package main | ||
| + | |||
| import ( | import ( | ||
| " | " | ||
| - | " | ||
| ) | ) | ||
| - | // Variable anlegen | + | func main() { |
| - | age int = 3; | + | |
| + | age := 3; | ||
| - | // switchen | + | |
| - | switch age { | + | switch age { |
| - | case 1: fmt.Println(" | + | case 1: fmt.Println(" |
| - | case 2: fmt.Println(" | + | case 2: fmt.Println(" |
| - | case 3: fmt.Println(" | + | case 3: fmt.Println(" |
| - | case 4: fmt.Println(" | + | case 4: fmt.Println(" |
| - | default: | + | default: |
| + | } | ||
| } | } | ||
| </ | </ | ||
| + | === Ausführen === | ||
| + | [[https:// | ||
| ===== Java ===== | ===== Java ===== | ||
| + | === Das Programm === | ||
| <code java> | <code java> | ||
| public class Switcher { | public class Switcher { | ||
| Line 108: | Line 131: | ||
| } | } | ||
| } | } | ||
| + | </ | ||
| + | === Kompilieren und ausführen === | ||
| + | Die Datei Switcher.java erstellen und so ausführen: | ||
| + | <code bash> | ||
| + | javac Switcher.java | ||
| + | java Switcher | ||
| </ | </ | ||
| ===== Javascript ===== | ===== Javascript ===== | ||
| + | === Das Programm === | ||
| <code javascript> | <code javascript> | ||
| < | < | ||
| Line 132: | Line 162: | ||
| </ | </ | ||
| </ | </ | ||
| + | === Ausführen === | ||
| + | Den Code in die Datei switch.html kopieren und mit dem Browser öffnen | ||
| ===== Perl ===== | ===== Perl ===== | ||
| + | === Das Programm === | ||
| <code perl> | <code perl> | ||
| # | # | ||
| Line 154: | Line 187: | ||
| </ | </ | ||
| - | ===== Python3 ===== | + | === Ausführen |
| - | In Python gibt es kein switch | + | Die Datei switch.pl erstellen und so ausführen: |
| + | <code bash> | ||
| + | perl switch.pl | ||
| + | </ | ||
| ===== PHP ===== | ===== PHP ===== | ||
| + | === Das Programm === | ||
| <code php> | <code php> | ||
| <?php | <?php | ||
| Line 173: | Line 210: | ||
| } | } | ||
| </ | </ | ||
| + | === Ausführen === | ||
| + | Die Datei switch.php erstellen und so ausführen: | ||
| + | <code bash> | ||
| + | php switch.php | ||
| + | </ | ||
| + | |||
| + | ===== Python3 ===== | ||
| + | In Python gibt es kein switch im eigentlichen Sinne. Mit ein bisschen Tricksen bekommt man trotzdem eines hin. Das wird hier aber ausgelassen. | ||
switch.1498572221.txt.gz · Last modified: 2017/06/27 16:03 by gg
