GoConqr has a new look! Let us know what you think.

Mind map

Loops

John Hair English

Map content

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.

Information

Description
Mind Map on Loops, created by John Hair on 26/04/2018.
Created by
John Hair
Views
1
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?