Skip to Content
Raku学习手册
book

Raku学习手册

by brian d foy
October 2020
Beginner to intermediate
499 pages
9h 13m
Chinese
China Electric Power Press Ltd.
Content preview from Raku学习手册
93
5
基本代码块
Block
就是把多个语句组合为一个东西。按我在前言中所说的,实际上你已经使用过
一些代码块。现在来更详细地分析这些代码块。这一章会介绍基础知识,然后逐步
过渡到简单的子例程。这一章中要了解的内容只是为了帮助你学习接下来的几章,
11
章还会做更多介绍。
5.1
代码块
代码块(
Block
)是一组用大括号括起来的语句。你已经使用
loop
重复执行过一组
语句。你还用
if-else
构,每个分支分别使用一个
Block
,而且只会执行其中的
一个
Block
loop { ... }
if $n %% 2 { put "Even!" }
else { put "Odd!" }
裸块(
bare block
)是指外面没有控制关键字的代码块。它在
sink
上下文中(
sink
示只有输入没有输出的一个“槽”),因为对它的结果不做任何处理。它会提供一
个作用域,而且会立即运行一次。其结果是
Block
中最后计算的表达式(不一定是
最后一个词法表达式)。下面是一个什么也不做的简单裸块:
{ ; }
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

可编程网络自动化

可编程网络自动化

Jason Edelman, Scott S. Lowe, Matt Oswalt
程序员学数据结构

程序员学数据结构

Posts & Telecom Press, William Smith
R深度学习权威指南

R深度学习权威指南

Posts & Telecom Press, Joshua F. Wiley
AI工程

AI工程

Chip Huyen

Publisher Resources

ISBN: 9787519848002