While Statement Assignment Help

Assignment Help: >> Elements of Java - While Statement

While

The while lope is Java's most fundamental looping statement.  While repeats a statement or block while its controlling expression is true. Below is its common form.

while (condition) {

/ / body of loop

}

The condition could be any boolean expression. A body of the loop will be executed as long as the conditional expression is true.   Whenever condition becomes false the control passes to the next line of code instantly following the loop. If only a single statement is starting repeated the curly braces are unnecessary.

The given below is a while loop which counts down from 10, printing exactly ten lines of "tick".

/ / Demonstrate the while loop.

class while{

public static void main (String args [ ] ) {

int n = 10; while (n > 0) {

System.out.println ("tick" + n);

n - -;

}

}

}

whenever you execute this program, it will "tick" ten times:

tick 10

tick 9

tick 8

tick 7

tick 6

tick 5

tick 4

tick 3

tick 2

tick 1

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd