Friday, 16 January 2015

Week 31: January 12-16 Exercise 1

Hi!

       On monday, I'm late because of something I can't remember. But we made another exercise and nobody got this in our batch. And then on the next day, I did it! Yes! 


     Here is our exercise 1:



The While Loop

 A while loop is a control structure that allows you to repeat a task a certain number of times.

Syntax:

The syntax of a while loop is:
while(Boolean_expression)
{
   //Statements
}
When executing, if the boolean_expression result is true, then the action inside the loop will be executed. 
This will continue as long as the expression result is true.
Here, key point of the while loop is that the loop might not ever run. 
When the expression is tested and the result is false, the loop body will be skipped 
and the first statement after the while loop will be executed.

Example:

public class Test {

   public static void main(String args[]) {
      int x = 10;

      while( x < 20 ) {
         System.out.print("value of x : " + x );
         x++;
         System.out.print("\n");
      }
   }
}
This would produce the following result:
value of x : 10
value of x : 11
value of x : 12
value of x : 13
value of x : 14
value of x : 15
value of x : 16
value of x : 17
value of x : 18
value of x : 19
Taken from http://www.tutorialspoint.com/java/java_loop_control.htm
signing off...



0 comments:

Post a Comment

// Posted by :Unknown // On :Friday, 16 January 2015

Hi!

       On monday, I'm late because of something I can't remember. But we made another exercise and nobody got this in our batch. And then on the next day, I did it! Yes! 


     Here is our exercise 1:



The While Loop

 A while loop is a control structure that allows you to repeat a task a certain number of times.

Syntax:

The syntax of a while loop is:
while(Boolean_expression)
{
   //Statements
}
When executing, if the boolean_expression result is true, then the action inside the loop will be executed. 
This will continue as long as the expression result is true.
Here, key point of the while loop is that the loop might not ever run. 
When the expression is tested and the result is false, the loop body will be skipped 
and the first statement after the while loop will be executed.

Example:

public class Test {

   public static void main(String args[]) {
      int x = 10;

      while( x < 20 ) {
         System.out.print("value of x : " + x );
         x++;
         System.out.print("\n");
      }
   }
}
This would produce the following result:
value of x : 10
value of x : 11
value of x : 12
value of x : 13
value of x : 14
value of x : 15
value of x : 16
value of x : 17
value of x : 18
value of x : 19
Taken from http://www.tutorialspoint.com/java/java_loop_control.htm
signing off...



Leave a Reply

Subscribe to Posts | Subscribe to Comments

 

Blog Template by YummyLolly.com - Header made with PS brushes by gvalkyrie.deviantart.com
Sponsored by Free Web Space