Geeks With Blogs
Stephanie Grima C#, ASP.NET and my life.

 

While Statement

The while statement is continously executed a block of code, until the condition is not true anymore. The while statement is also called a loop since it executes repeatedly one after the other until the condition is not met anymore.

while (expression) {
     statement/s
}

A proper example of a while loop is the following:

int counter = 1;
string result = "";
while (counter < 11)
{
      result += "Count is: " + counter;
      counter++;
}

Explanation: While the counter is less than 11, therefore equal to ten, add to the result variable "Counter is : " and the counter amount. The value of counter changes with "counter++" which means: increment the value in counter by one.

 

Posted on Wednesday, October 29, 2008 7:25 PM C# , Java | Back to top


Comments on this post: [C#] [Java] Control Structures Part 3 :WHILE Statement

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Steffi | Powered by: GeeksWithBlogs.net