Shares
facebook sharing button Share
twitter sharing button Tweet
email sharing button Email
linkedin sharing button Share
reddit sharing button Share
tumblr sharing button Share
blogger sharing button Share
print sharing button Print
skype sharing button Share
sms sharing button Share
whatsapp sharing button Share
arrow_left sharing button
arrow_right sharing button
 Krivalar Tutorials 
Krivalar Tutorials

Java while loop in programming


<<Previous

Next >>





while statement

while is a conditional loop statement. The statements within the while block are executed only if the condition returns true.

while - Syntax


while(condition)
{
	statement;
}

while - Example


public class While {
public static void main(String a[]){
  int i=0;

  System.out.println(
		"\nbefore first while loop");
  while(i<10){
	System.out.print(
		"" + i + ",");
	i=i+1;
  }

  i=20;

  System.out.println(
		"\n\nbefore second while loop");
  while(i<10){
	System.out.print("" + i + ",");
	i=i+1;
  }
  System.out.println(
	"\nafter second while loop");
}
}

The above while loop prints:

before first while loop
0,1,2,3,4,5,6,7,8,9,

before second while loop

after second while loop


<<Previous

Next >>





















Searching using Binary Search Tree