Showing posts with label boolean. Show all posts
Showing posts with label boolean. Show all posts

Sunday, May 27, 2012

While loop

DOWNLOAD THE CODE: usingWhileLoops.java.zip

While is a type of loop. Statements inside of the loop will continue to repeat while the loop condition is true.

The while loop is primed with a boolean expression/condition. When the condition becomes false, the loop will stop.

while (condition) {
    // statements to loop.
}


The example below uses a while loop to increment the value of the int variable num. On each pass of the loop, num has 100 added to it. The loop will continue to execute while the value of num is less than or equal to the value of the int variable maxnum.


The output:


The loop condition can be any expression that return a boolean value.


"Java For Complete Beginners - while loops" ( http://bit.ly/JGnAII )

Wednesday, May 23, 2012

Boolean

The boolean datatype can store the value True or False.


Where a boolean has not been assigned a value, by default it's value is false.

The format for declaring a boolean variable is:

   Type identifier;

Where the Type is boolean and the identifier is exists:

   boolean exists;

...and where a value of true has been assigned:

   boolean exists = true;

You can declare a boolean in one statement and assign it a value in another statement:

    boolean exists;
   // other statements...
   exists = true;

Tuesday, March 27, 2012

A handful of data types & variables

String
Any collection of keyboard characters.

Boolean
A true or false value.

Char
A single keyboard character.

int
A whole number between -2,147,483,648 and 2,147,484,647