Syntax

Java While Loop Syntax

In Java, while loop: repeats while a condition is true — while (x < 10) { x++; }

Quick Answer

Syntax
while (x < 10) { x++; }
JavaSyntax

While Loop

Code example
while (x < 10) { x++; }

Repeats while a condition is true.

Learn More

How to while loop in Java

  1. Open your Java file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Java While Loop Syntax

Use while (x < 10) { x++; }.

Related Syntax References

Frequently asked questions

What is the Java syntax for while loop?

Use this pattern: while (x < 10) { x++; }

Can I copy this Java code example?

Yes. Use Copy code and adapt the example to your program.

Is this Java syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify