# Java: Loops - 'while' and 'for'

## Purpose

The purpose of loop statements is to repeat something many times. There are three kinds of loop statements in Java: `while`, `for`, and `do..while`.

## Most important loops: 'while' and 'for'

We will only discuss the two most common kinds of loop statements:

- 'while' Statement
- 'for' Statement

## Similar to the 'if' statement

There are three general ideas that you will see in many parts of Java:

- use of braces `{}` to enclose multiple statements
- indentation
- boolean (true/false) conditions.

## Use of braces {} for more than one statement

If the body of a loop has more than one statement, you must put the statements inside braces. If there is only one statement, it is not necessary to use braces `{}`. However, many programmers think it is a good idea to always use braces for loops (and ifs).

## Indentation of loops

All statements inside a loop should be indented 2-4 spaces (the same as an `if` statement.

## boolean true/false conditions

True/false (boolean) expressions control both loops and the if statement.