Friday, June 29, 2018

While loop

WhileThe while loop evaluates a condition and executes statements, depending on
whether the condition is satisfied. The loop continues to check the condition, and
as long as the condition is true, it continues to execute the statements. As soon as
the condition becomes false, the statement is exited. The syntax is as follows:
while (condition)
{
//statement;
}

This is a simple while statement that counts from 1 to 5.int counter = 1;
while (counter <= 5)
{
print counter;
counter ++; // This increments the counter by 1
}
pause;
Result:
1
2
3
4
5
HINT: The previous example uses the counter++ which can increment any
integer by 1. You can also set the increment to any value by using the
variable+=<# to increment> syntax. For example:
counter+=2; //This increments the counter variable by two every time.
Notice the condition is evaluated before the statements are executed. In the
previous example, it means that if the counter variable is greater than five when it
reaches this loop, it does not execute. Therefore, a
while statement can be
executed zero or more times.


Best Regards,
Hossein Karimi

No comments:

Post a Comment

Configure the Firewall on the Enterprise Portal Server

After you install Enterprise Portal, enable Web Server (HTTP) in Windows Firewall. If you do not enable the web server in Windows Firewall...