GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Mindmap

Loops

John Hair Englisch

Inhalt der Mindmap

Loops

  1. While loops: A while loop executes the body of the loop as long as (or while) a Boolean condition is true. When the condition is false execution continues after the body of the while loop.

    • For example: while (true) { System.out.println("This is a loop that never ends"); }
  2. For loops: Iterates through for a certain amount of time. You can put in a set number, or have it for the length of a variable/object

    • For example: (loop 5 times (5, 4, 3, 2, 1)) for (int i = 5; i > 0; i--) { }
  3. Nested loops: A nested loop has one loop inside of another. These are typically used for working with two dimensions such as printing stars in rows and columns as shown below.

    • For example:for (int row = 0; row < 5; row++) { for (int col = 0; col < 10; col++) { System.out.print("*"); } System.out.println(); }
  4. Common Mistakes

    • Forgetting to change the thing you are testing in a while loop and ending up with an infinite loop.
    • Getting the start and end conditions wrong on the for loop. This will often result in you getting an out of bounds error. An out of bounds error occurs when you try to access past the end of a string.
    • Jumping out of a loop too early by using one or more return statements inside of the loop.

Informationen

Beschreibung
Mindmap am Loops, erstellt von John Hair am 26/04/2018.
Erstellt von
John Hair
Aufrufe
1
Bewertung

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck