ifelse
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| ifelse [2017/06/28 12:28] – [Ausführen] gg | ifelse [2017/06/28 13:29] (current) – gg | ||
|---|---|---|---|
| Line 5: | Line 5: | ||
| Natürlich würde man normalerweise die beiden Strings nicht einfach setzen, sondern aus einer Datenbank, als Funktionsparameter oder Programmparameter einlesen. Das aber würde den Rahmen hier sprengen. | Natürlich würde man normalerweise die beiden Strings nicht einfach setzen, sondern aus einer Datenbank, als Funktionsparameter oder Programmparameter einlesen. Das aber würde den Rahmen hier sprengen. | ||
| ===== Bash ===== | ===== Bash ===== | ||
| - | ==== Das Programm | + | === Das Programm === |
| <code bash> | <code bash> | ||
| #!/bin/bash | #!/bin/bash | ||
| Line 15: | Line 15: | ||
| # Vergleichen | # Vergleichen | ||
| if [ " | if [ " | ||
| - | # ausgabe, wenn die beiden Strings gleich sind | + | |
| - | echo "$one is equal to $two" | + | echo "$one is equal to $two" |
| else | else | ||
| - | # ausgabe, wenn die beiden Strings nicht gleich sind | + | |
| - | echo "$one is not equal to $two" | + | echo "$one is not equal to $two" |
| fi | fi | ||
| </ | </ | ||
| - | ==== Ausführen | + | === Ausführen === |
| Die Datei ifelse.sh mit obigen erstellen und folgendes ausführen: | Die Datei ifelse.sh mit obigen erstellen und folgendes ausführen: | ||
| <code bash> | <code bash> | ||
| Line 30: | Line 30: | ||
| </ | </ | ||
| ===== C++ ===== | ===== C++ ===== | ||
| + | === Das Programm === | ||
| <code cpp> | <code cpp> | ||
| #include < | #include < | ||
| Line 35: | Line 36: | ||
| int main() { | int main() { | ||
| - | // Variablen anlegen | + | |
| - | const char* one = " | + | const char* one = " |
| - | const char* two = " | + | const char* two = " |
| - | // Vergleichen | + | |
| - | if(!strcmp(one, | + | if(!strcmp(one, |
| - | // Ausgabe, wenn die beiden Strings ident sind | + | // Ausgabe, wenn die beiden Strings ident sind |
| - | printf(" | + | printf(" |
| - | } else { | + | } else { |
| - | // Ausgabe, wenn die beiden Strings nicht ident sind | + | // Ausgabe, wenn die beiden Strings nicht ident sind |
| - | printf(" | + | printf(" |
| - | } | + | } |
| } | } | ||
| + | </ | ||
| + | === Kompilieren und ausführen === | ||
| + | Die Datei ifelse.cpp mit obigen Inhalt erstellen und folgendes ausführen: | ||
| + | <code bash> | ||
| + | g++ -Wall -g -std=c++14 ifelse.cpp -o ifelse # kompilieren | ||
| + | ./ | ||
| </ | </ | ||
| ===== C# ===== | ===== C# ===== | ||
| + | === Das Programm === | ||
| <code csharp> | <code csharp> | ||
| using System; | using System; | ||
| Line 56: | Line 64: | ||
| namespace IfStatements | namespace IfStatements | ||
| { | { | ||
| - | class ShowIf | + | |
| - | { | + | { |
| - | static void Main() | + | static void Main() |
| - | { | + | { |
| - | // Variablen anlegen | + | // Variablen anlegen |
| - | string one = " | + | string one = " |
| - | string two = " | + | string two = " |
| - | // Vergleichen | + | |
| - | if(one.equals(two)) { | + | if(one.equals(two)) { |
| - | // Ausgabe, wenn die beiden Strings ident sind | + | // Ausgabe, wenn die beiden Strings ident sind |
| - | Console.WriteLine(one+" | + | Console.WriteLine(one+" |
| - | } else { | + | } else { |
| - | // Ausgabe, wenn die beiden Strings nicht ident sind | + | // Ausgabe, wenn die beiden Strings nicht ident sind |
| - | Console.WriteLine(one+" | + | Console.WriteLine(one+" |
| - | } | + | } |
| - | } | + | } |
| - | } | + | } |
| } | } | ||
| </ | </ | ||
| ===== Golang ===== | ===== Golang ===== | ||
| + | === Das Programm === | ||
| <code go> | <code go> | ||
| import ( | import ( | ||
| Line 99: | Line 108: | ||
| } | } | ||
| </ | </ | ||
| + | === Kompilieren und ausführen === | ||
| + | Den obigen Quelltext [[https:// | ||
| ===== Java ===== | ===== Java ===== | ||
| + | === Das Programm === | ||
| <code java> | <code java> | ||
| - | public class HelloWorld | + | public class IfElse |
| - | public static void main(String[] args) { | + | public static void main(String[] args) { |
| - | // Variablen anlegen | + | // Variablen anlegen |
| - | String one = new String(" | + | String one = new String(" |
| - | String two = new String(" | + | String two = new String(" |
| - | // Vergleichen | + | |
| - | if(one.equals(two)) { | + | if(one.equals(two)) { |
| - | // Ausgabe, wenn die beiden Strings ident sind | + | // Ausgabe, wenn die beiden Strings ident sind |
| - | printf(" | + | |
| - | } else { | + | } else { |
| - | // Ausgabe, wenn die beiden Strings nicht ident sind | + | // Ausgabe, wenn die beiden Strings nicht ident sind |
| - | printf(" | + | |
| - | } | + | } |
| - | } | + | } |
| } | } | ||
| + | </ | ||
| + | === Kompilieren und ausführen === | ||
| + | Die Datei IfElse.java mit obigen Quelltext erstellen und folgendes ausführen: | ||
| + | <code bash> | ||
| + | javac IfElse.java | ||
| + | java IfElse | ||
| </ | </ | ||
| ===== Javascript ===== | ===== Javascript ===== | ||
| + | === Das Programm === | ||
| <code javascript> | <code javascript> | ||
| < | < | ||
| Line 143: | Line 162: | ||
| </ | </ | ||
| </ | </ | ||
| + | |||
| + | === Ausführen === | ||
| + | Die Datei ifelse.html mit obigen Inhalt erstellen und im Browser öffnen | ||
| ===== Perl ===== | ===== Perl ===== | ||
| + | === Das Programm === | ||
| <code perl> | <code perl> | ||
| - | # | ||
| use strict; | use strict; | ||
| Line 157: | Line 179: | ||
| # Vergleichen | # Vergleichen | ||
| if($one eq $two) { | if($one eq $two) { | ||
| - | # Ausgabe, wenn die beiden Variablen ident sind | + | |
| - | print $one." equals " | + | print $one." equals " |
| } else { | } else { | ||
| - | # Ausgabe, wenn die beiden Variablen nicht ident sind | + | |
| - | print $one." equals not " | + | print $one." equals not " |
| } | } | ||
| + | </ | ||
| + | === Ausführen === | ||
| + | Die Datei ifelse.pl erstellen und folgendes ausführen: | ||
| + | <code bash> | ||
| + | perl ifelse.pl | ||
| </ | </ | ||
| ===== PHP ===== | ===== PHP ===== | ||
| + | === Das Programm === | ||
| <code php> | <code php> | ||
| <?php | <?php | ||
| Line 175: | Line 203: | ||
| // Vergleichen | // Vergleichen | ||
| if($one === $two) { | if($one === $two) { | ||
| - | // Ausgabe, wenn die beiden Strings ident sind | + | |
| - | echo "one equals two"; | + | echo "one equals two"; |
| } else { | } else { | ||
| - | // Ausgabe, wenn die beiden Strings nicht ident sind | + | |
| - | echo "one equals not two"; | + | echo "one equals not two"; |
| } | } | ||
| + | </ | ||
| + | === Ausführen === | ||
| + | Die Datei ifelse.php erstellen und so ausführen: | ||
| + | <code bash> | ||
| + | php ifelse.php | ||
| </ | </ | ||
| ===== Python3 ===== | ===== Python3 ===== | ||
| + | === Das Programm === | ||
| <code python> | <code python> | ||
| - | # | ||
| # Variablen anlegen | # Variablen anlegen | ||
| Line 193: | Line 226: | ||
| # Vergleichen | # Vergleichen | ||
| if one == two: | if one == two: | ||
| - | # Ausgabe, wenn die beiden Strings ident sind | + | |
| - | print(one+" | + | print(one+" |
| else: | else: | ||
| - | # Ausgabe, wenn die beiden Strings nicht ident sind | + | |
| - | print(one+" | + | print(one+" |
| + | </ | ||
| + | |||
| + | === Ausführen === | ||
| + | Die Datei ifelse.py erstellen und so ausführen: | ||
| + | <code python> | ||
| + | python3 ifelse.py | ||
| </ | </ | ||
ifelse.1498645701.txt.gz · Last modified: 2017/06/28 12:28 by gg
