¡GoConqr estrena diseño! Cuéntanos qué te parece.

Mapa mental

Loops

John Hair Inglés

Contenido del mapa

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.

Información

Descripción
Mapa Mental sobre Loops, creado por John Hair el 26/04/2018.
Creado por
John Hair
Visitas
1
Valoración

Escríbenos

¿Sobre qué es tu mensaje?

¿Qué te parece el nuevo diseño?

¿Te gusta?