Using "while" and "do..while" statement.

วันจันทร์ที่ 14 กันยายน พ.ศ. 2552

- "while" is statement for looping same "for" statment. It has format follow.

$a = 0;

while ($a <3) (

$a;

print $a. ",";

)

# Values are shown 1, 2, 3 due to 0 $ a start when loop while on the condition that if $ a is less than 3 in order to make the blog. Over conditions. Will provide variable $ a (Added 1 value) Therefore, when this variable $ a = 1 then display output. Then to check the conditions while until conditions are false.

- do ... while a function like while (condition) () command, but do .. while the first block in order to do do .. while before gradually to check conditions into account, such as when finishing.

$a = 3;

do (

print $ a. ",";

$a--;

) While ($a <3);

# When viewing the variable $ a is 3 and will be valuable in terms of checks in order while the check that if $ a <3 to do in order blog. But in this case, a command do ... while when set to variable $ a = 3 will be made on the blog do ... while the command immediately without prior conditions examined. When a command in the block and then erase the value $ a to a variable cost, so now at $ a = 2, then in order to check conditions while on the set. But in this case, the year of the endless Blue (overflow) to describe, but easy to understand. This command has raised the issue.

0 ความคิดเห็น:

แสดงความคิดเห็น

 
 
 
 
Copyright © Basic Perl