for
This is an old revision of the document!
−Table of Contents
for Schleife
Die for Schleife ist flexibler, als eine while Schleife. Sie ist lesbarer.
Die folgenden Beispiele zählen von 1 bis 10.
Bash
#!/bin/bash for i in `seq 1 10`; do echo "The counter is $i" done
C++
#include <iostream> int main() { for(int i = 1; i <= 10; i++) { printf("%d %d%s", "The counter is", i, "\n" } }
C#
using System; namespace ForLoop { class ShowFor { static void Main() { for(int i = 1; i <= 10; i++) { System.WriteLine("The counter is "+i); } } } }
Golang
In go ist so ziemlich alles eine for Schleife. Es kommt darauf an, wie man es hin schreibt.
package main import ( "fmt" ) func main() { for i:=1; i<=10; i++ { fmt.Println("The counter is ", i) } }
Java
public class WhileLoop { public static void main(String[] args) { // Variable anlegen int counter = 0; while (counter < 10) { System.out.println("The counter is "+counter); counter++; } }
Javascript
<!DOCTYPE HTML> <!-- HTML Grundstruktur --> <html> <body> <script> // Variable anlegen var counter = 0; while (counter < 10) { alert("The counter is "+counter); counter++; } </script> </body> </html>
Perl
#!/usr/bin/perl use strict; use warnings; my $counter = 0; while ($counter < 10) { print "The counter is $counter\n"; $counter += 1; }
PHP
<?php // Variable anlegen $counter = 0; while ($counter < 10) { echo "The counter is $counter\n"; $counter++; }
Python3
#!/usr/bin/python3 counter = 0 while counter < 10: print("The counter is "+str(counter)) counter += 1
for.1498580763.txt.gz · Last modified: 2017/06/27 18:26 by gg