Sie sind auf Seite 1von 5

News

Knowledge Base

ANDROID

Deals

CORE JAVA

Job Board

About

DESKTOP JAVA

ENTERPRISE JAVA

JAVA BASICS

JVM LANGUAGES

Search...

SOFTWARE DEVELOPMENT

Home Java Basics while loop Simple while loop

ABOUT BYRON KIOURTZOGLOU


Byron is a master software engineer working in the IT and Telecom domains. He is an applications developer in a wide variety of
applications/services. He is currently acting as the team leader and technical architect for a proprietary service creation and integration
platform for both the IT and Telecom industries in addition to a in-house big data real-time analytics solution. He is always fascinated by
SOA, middleware services and mobile development. Byron is co-founder and Executive Editor at Java Code Geeks.

Simple while loop


Posted by: Byron Kiourtzoglou in while loop November 11th, 2012

With this example we are going to demonstrate how to use a simple


while

statement in Java. The


while

statement continually executes a block of statements while a particular condition is true. In short, to use a simple
while

NEWSLETTER

DEVOPS

loop you should:

NEWSLETTER

Create a
while

statement that evaluates an expression, which must return a boolean value and has a
statement.
If the expression evaluates to true, the while statement executes the statement in the
while

block.
The

161973 insiders are already enjoying


weekly updates and complimentary
whitepapers!

Join them now to gain exclusive


access to the latest news in the Java

world, as well as insights about Android,


Scala, Groovy and other related technologies.

Email address:
Your email address

while

statement continues testing the expression and executing its block until the expression evaluates to false.

Sign up

Lets take a look at the code snippet that follows:


01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19

package com.javacodegeeks.snippets.basics;

public class SimpleWhileLoopExample {

public static void main(String[] args) {

int i = 0;
int max = 5;

System.out.println("Counting to " + max);

while (i < max) {


i++;
System.out.println("i is : " + i);
}

Output:
Counting to 5
i is : 1
i is : 2
i is : 3
i is : 4
i is : 5

JOIN US
With 1,240,600 monthly
unique visitors and over
500 authors we are
placed among the top Java
related sites around.
Constantly being on the
lookout for partners; we
encourage you to join us.
So If you have a blog with
unique and interesting
content then you should check out our JCG
partners program. You can also be a guest writer
for Java Code Geeks and hone your writing skills!


This was an example of how to use a simple
while

loop in Java.

Tagged with:

JAVA BASICS

WHILE LOOP

Do you want to know how to develop your skillset to become a Java


Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!

1. JPA Mini Book


2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design

and many more ....

Email address:
Your email address

Sign up

CAREER OPPORTUNITIES
REMOTE Senior Java DeveloperABC Financial
Services Inc
Remote
Apr, 04
Software Engineer - Java Developer - Entry
LevelFICO
San Jose, CA
Apr, 18
Programmer/Analyst IIIUCLA
Los Angeles, CA
Apr, 22
Software Development EngineerIntel

Hillsboro, OR
Apr, 14
Software Development EngineerIntel
Plano, TX
Apr, 20
Software Development EngineerIntel
Santa Clara, CA
Apr, 12
Google for Work, Software EngineerGoogle
Mountain View, CA
Apr, 21
Programmer Analyst, SeniorPacific Gas & Electric
San Ramon, CA
Apr, 15
Senior Data Platform Site Reliability EngineerTesla
Motors
Palo Alto, CA
Apr, 20
Junior ProgrammerAT&T
Columbia, MD
Apr, 19
1
2
...
7029

Freelance

Keyword ...

Full-time

Location ...

Intership

Country ...

Part-time
All

Filter Results
jobs by

KNOWLEDGE BASE

HALL OF FAME

Courses

Android Alert Dialog Example

News

Android OnClickListener Example

Resources

How to convert Character to String and a


String to Character Array in Java

Tutorials
Whitepapers

Java Inheritance example


Java write to File Example

THE CODE GEEKS NETWORK


.NET Code Geeks
Java Code Geeks
System Code Geeks
Web Code Geeks

java.io.FileNotFoundException How to
solve File Not Found Exception

ABOUT JAVA CODE GEEKS


JCGs (Java Code Geeks) is an independent online community focused on creating the
ultimate Java to Java developers resource center; targeted at the technical architect,
technical team lead (senior developer), project manager and junior developers alike.
JCGs serve the Java, SOA, Agile and Telecom communities with daily news written by
domain experts, articles, tutorials, reviews, announcements, code snippets and open
source projects.

DISCLAIMER
All trademarks and registered trademarks appearing on Java Code Geeks are the
property of their respective owners. Java is a trademark or registered trademark of
Oracle Corporation in the United States and other countries. Examples Java Code Geeks
is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.

java.lang.arrayindexoutofboundsexception
How to handle Array Index Out Of
Bounds Exception
java.lang.NoClassDefFoundError How
to solve No Class Def Found Error
JSON Example With Jersey + Jackson
Spring JdbcTemplate Example

Examples Java Code Geeks and all content copyright 2010-2016, Exelixis Media P.C. | Terms of Use | Privacy Policy | Contact

Das könnte Ihnen auch gefallen