- Parrot 教程
- Parrot - 主頁
- Parrot - 概述
- Parrot - 安裝
- Parrot - 說明
- Parrot - 垃圾回收
- Parrot - 資料型別
- Parrot - 暫存器
- Parrot - 操作
- Parrot - 分支
- Parrot 示例
- Parrot - 示例
- Parrot 資源
- Parrot - 快速指南
- Parrot - 有用資源
Parrot - 分支
在沒有流控制的情況下,程式碼會有些枯燥;對於初學者,Parrot 瞭解分支和標籤。分支操作相當於 Perl 中的 goto
branch TERRY
JOHN: print "fjords\n"
branch END
MICHAEL: print " pining"
branch GRAHAM
TERRY: print "It's"
branch MICHAEL
GRAHAM: print " for the "
branch JOHN
END: end
它還可以執行簡單的測試,以檢視暫存器是否包含真值
set I1, 12
set I2, 5
mod I3, I2, I2
if I3, REMAIND, DIVISOR
REMAIND: print "5 divides 12 with remainder "
print I3
branch DONE
DIVISOR: print "5 is an integer divisor of 12"
DONE: print "\n"
end
以下是相比之下,Perl 中的樣子
$i1 = 12;
$i2 = 5;
$i3 = $i1 % $i2;
if ($i3) {
print "5 divides 12 with remainder ";
print $i3;
} else {
print "5 is an integer divisor of 12";
}
print "\n";
exit;
Parrot 運算子
我們有全系列的數字比較器:eq、ne、lt、gt、le 和 ge。請注意,你不能在不同型別的引數上使用這些運算子;你甚至可能需要在運算子字尾上新增 _i 或 _n,以告訴它你使用的是哪種型別引數,儘管在此時此刻,彙編器可以透過閱讀來推斷這一點。
廣告