Skip to content

Instantly share code, notes, and snippets.

@HamsterofDeath
Created March 28, 2023 12:55
Show Gist options
  • Save HamsterofDeath/ea8825fa3396991b50f473be963cbdb5 to your computer and use it in GitHub Desktop.
Save HamsterofDeath/ea8825fa3396991b50f473be963cbdb5 to your computer and use it in GitHub Desktop.
package superprof;
public class SchleifenBeispiel {
public static void main(String[] args) {
// Schleife 1: Code im Körper der Schleife
for (int i = 0; i < 5; ) {
aktion(i);
i++;
}
// Schleife 2: Code im Inkrement-Teil der Schleife
for (int i = 0; i < 5; aktion(i), i++) {
// Kein Code im Schleifenkörper
}
// Schleife 3: Code im Test-Teil der Schleife
for (int i = 0; (i < 5 && (aktion(i) || true)); i++) {
// Kein Code im Schleifenkörper
}
}
public static boolean aktion(int i) {
System.out.println(i);
return false; // Rückgabewert für Schleife 3
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment