while
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| while [2017/06/27 17:48] – [Perl] gg | while [2017/06/29 10:32] (current) – [Java] gg | ||
|---|---|---|---|
| Line 6: | Line 6: | ||
| ===== Bash ===== | ===== Bash ===== | ||
| + | === Das Programm === | ||
| <code bash> | <code bash> | ||
| #!/bin/bash | #!/bin/bash | ||
| Line 14: | Line 15: | ||
| let COUNTER=COUNTER+1 | let COUNTER=COUNTER+1 | ||
| done | done | ||
| + | </ | ||
| + | |||
| + | === Ausführen === | ||
| + | <code bash> | ||
| + | chmod +x while.sh # als ausführbar markiern | ||
| + | ./ | ||
| </ | </ | ||
| ===== C++ ===== | ===== C++ ===== | ||
| + | === Das Programm === | ||
| <code cpp> | <code cpp> | ||
| #include < | #include < | ||
| Line 26: | Line 34: | ||
| while (counter < 10) { | while (counter < 10) { | ||
| printf(" | printf(" | ||
| + | counter++; | ||
| } | } | ||
| } | } | ||
| + | </ | ||
| + | |||
| + | === Kompilieren und Ausführen === | ||
| + | Die Datei while.cpp erstellen und so ausführen: | ||
| + | <code bash> | ||
| + | g++ -Wall -g -std=c++14 while.cpp -o while # kompilieren | ||
| + | ./ | ||
| </ | </ | ||
| Line 34: | Line 50: | ||
| using System; | using System; | ||
| - | namespace | + | namespace |
| { | { | ||
| - | class ShowIf | + | class ShowWhile |
| { | { | ||
| static void Main() | static void Main() | ||
| Line 45: | Line 61: | ||
| while (counter < 10) { | while (counter < 10) { | ||
| System.WriteLine(" | System.WriteLine(" | ||
| + | counter++; | ||
| } | } | ||
| } | } | ||
| Line 52: | Line 69: | ||
| ===== Golang ===== | ===== Golang ===== | ||
| - | In go ist so ziemlich alles eine for Schleife. Es kommt darauf an, wie man es hin schreibt. | + | In go ist so ziemlich alles eine for Schleife. Es kommt nur darauf an, wie man es hin schreibt. |
| + | === Das Programm === | ||
| <code go> | <code go> | ||
| package main | package main | ||
| Line 71: | Line 89: | ||
| } | } | ||
| </ | </ | ||
| + | |||
| + | === Ausführen === | ||
| + | [[https:// | ||
| ===== Java ===== | ===== Java ===== | ||
| + | === Das Programm === | ||
| <code java> | <code java> | ||
| public class WhileLoop { | public class WhileLoop { | ||
| Line 81: | Line 103: | ||
| while (counter < 10) { | while (counter < 10) { | ||
| System.out.println(" | System.out.println(" | ||
| - | counter++ | + | counter++; |
| } | } | ||
| } | } | ||
| + | </ | ||
| + | |||
| + | === Kompilieren und ausführen === | ||
| + | Die Datei WhileLoop.java mit obigen Inhalt erstellen und so starten | ||
| + | <code bash> | ||
| + | javac WhileLoop.java # kompilieren | ||
| + | java WhileLoop | ||
| </ | </ | ||
| ===== Javascript ===== | ===== Javascript ===== | ||
| + | === Das Programm === | ||
| <code javascript> | <code javascript> | ||
| < | < | ||
| Line 104: | Line 134: | ||
| </ | </ | ||
| </ | </ | ||
| + | |||
| + | === Ausführen === | ||
| + | Den obigen Code in die Datei while.html einfügen und im Browser öffnen | ||
| ===== Perl ===== | ===== Perl ===== | ||
| + | === Das Programm === | ||
| <code perl> | <code perl> | ||
| # | # | ||
| Line 118: | Line 152: | ||
| $counter += 1; | $counter += 1; | ||
| } | } | ||
| + | </ | ||
| + | === Ausführen === | ||
| + | Die Datei while.pl erstellen und so ausführen: | ||
| + | <code bash> | ||
| + | perl while.pl | ||
| </ | </ | ||
| - | |||
| - | ===== Python3 ===== | ||
| - | In Python gibt es kein switch im eigentlichen Sinne. Mit ein bisschen Tricksen bekommt man trotzdem eines hin. Das wird hier aber ausgelassen. | ||
| ===== PHP ===== | ===== PHP ===== | ||
| + | === Das Programm === | ||
| <code php> | <code php> | ||
| <?php | <?php | ||
| // Variable anlegen | // Variable anlegen | ||
| - | $age = 3; | + | $counter |
| - | // switchen | + | while ($counter < 10) { |
| - | switch | + | echo "The counter is $counter\n"; |
| - | | + | |
| - | | + | |
| - | case 3: echo "Du bist drei Jahre alt"; break; | + | |
| - | case 4: echo "Du bist vier Jahre alt"; break; | + | |
| - | default: echo "Ich kann nicht feststellen wie alt du bist. Bitte eine Zahl von 1-4 eingeben"; | + | |
| } | } | ||
| + | </ | ||
| + | |||
| + | === Ausführen === | ||
| + | Die Datei while.php mit obigen Inhalt erstellen und wie folgt ausführen: | ||
| + | <code bash> | ||
| + | php while.php | ||
| + | </ | ||
| + | |||
| + | ===== Python3 ===== | ||
| + | === Das Programm === | ||
| + | <code python> | ||
| + | # | ||
| + | |||
| + | counter = 0 | ||
| + | |||
| + | while counter < 10: | ||
| + | print(" | ||
| + | counter += 1 | ||
| + | </ | ||
| + | |||
| + | === Ausführen === | ||
| + | Die Datei while.py mit dem obigen Code erstellen und ausführen: | ||
| + | |||
| + | <code bash> | ||
| + | python3 while.py | ||
| </ | </ | ||
while.1498578527.txt.gz · Last modified: 2017/06/27 17:48 by gg
