ChucK初步(6)
control structures
- if / else
- while & do…while…
- until
- for
- break / continue
Control Structures
ChucK includes standard control structures similar to those in most programming languages. A condition (of type ‘int’) is evaluated and then a proceeding block is potentially executed. Blocks are separated either by semicolons(分号) or by curly brackets(花括号).
if / else
The if statement executes a block if the condition is evaluated as non-zero.
if( condition )
{// insert code here
}
In the above code, condition is any expression that evaluates to an int. (条件是一个值为整数的表达式)
The else statement(声明) can be put after the if block to handle the case where the condition evaluates(求值) to 0.
if( condition )
{// your code here
}
else
{// your other code here
}
If statements can be nested(嵌套).
while & do…while…
// here is an infinite loop
while( true )
{// your code loops forever!// (sometimes this is desirable because we can create// infinite time loops this way, and because we have// concurrency)
}
do {// your code executes here at least once
} while( condition );
A few more points:
while
statements can be nested.- see
break/continue
for additional(附加的) control over your loops
until
The until statement is the opposite of while, semantically(语义地). A until loop repeatedly executes the body until the condition evaluates as non-zero.
// an infinite loop
until( false )
{// your great code loops forever!
}
A few more points:
while
statements can be nested.- see
break/continue
for additional(附加的) control over your loops
for
A loop that iterates(迭代) a given number of times.(迭代给定次数) A temporary(暂时的) variable(变量) is declared that keeps track(跟踪) of the current index and is evaluated and incremented at each iteration(迭代).
// for loop
for( 0 => int foo; foo < 4 ; foo++ )
{// debug-print value of 'foo'<<<foo>>>;
}
break / continue
Break
allows the program flow to jump out of a loop.
// infinite loop
while( 1 )
{if( condition ) break;
}
Continue
allows a loop to continue looping but not to execute(实行) the rest of the block for the iteration where continue was executed.(跳过当前的循环)
// another infinite loop
while( 1 )
{// check conditionif( condition )continue;// some great code that may get skipped (if continue is taken)
}
ChucK初步(6)相关推荐
- TensorRT 7.2.1开发初步
TensorRT 7.2.1开发初步 TensorRT 7.2.1开发人员指南演示了如何使用C ++和Python API来实现最常见的深度学习层.它显示了如何采用深度学习框架构建现有模型,并使用该模 ...
- SOC,System on-a-Chip技术初步
SOC,System on-a-Chip技术初步 S O C(拼作S-O-C)是一种集成电路,它包含了电子系统在单个芯片上所需的所有电路和组件.它可以与传统的计算机系统形成对比,后者由许多不同的组件组 ...
- 《OpenCV3编程入门》学习笔记3 HighGUI图形用户界面初步
第3章 HighGUI图形用户界面初步 3.1 图像的载入.显示和输出到文件 1.OpenCV命名空间2种访问方法 (1)代码开头加:usingnamespace cv; (2)每个类或函数前加:cv ...
- 初步判断内存泄漏方法
有时候,内存泄漏不明显,或者怀疑系统有内存泄漏,我们可以通过下面介绍的方法初步确认系统是否存在内存泄漏. 首先在Java命令行中增加-verbose:gc参数, 然后重新启动java进程. 当系统运行 ...
- android蓝牙4.0(BLE)开发之ibeacon初步
一个april beacon里携带的信息如下 ? 1 <code class=" hljs ">0201061AFF4C0002159069BDB88C11416BAC ...
- 游戏AI之初步介绍(0)
目录 游戏AI是什么? 游戏AI和理论AI 智能的假象 (更新)游戏AI和机器学习 介绍一些游戏AI 4X游戏AI <求生之路>系列 角色扮演/沙盒游戏中的NPC 游戏AI 需要学些什么? ...
- 【转】ibatis的简介与初步搭建应用
[转]ibatis的简介与初步搭建应用 一.ibatis的简介 ibatis是什么东西就不介绍了,自己去找谷老师. 这里讲下自己的使用体会.之前自己学过Hibernate,是看尚学堂的视频教学的,看完 ...
- 初步了解:使用JavaScript进行表达式(De Do Do Do,De Da Da Da)
by Donavon West 由Donavon West 初步了解:使用JavaScript进行表达式(De Do Do Do,De Da Da Da) (A first look: do expr ...
- 存储过程和存储函数初步
2019独角兽企业重金招聘Python工程师标准>>> 存储过程和函数初步 简单的来说,存储过程就是一条或者多条 SQL 语句的集合,可视为批处理文件,但是其作用不仅限于批处理. # ...
- 【spring框架】spring整合hibernate初步
spring与hibernate做整合的时候,首先我们要获得sessionFactory. 我们一般只需要操作一个sessionFactory,也就是一个"单例",这一点很适合交给 ...
最新文章
- grub-和grub-troubleshootting
- vc6.0上安装qt插件
- Kafka简介、安装
- Spark笔记:RDD基本操作(上)
- CF1338D:Nested Rubber Bands(树形dp)
- 【OpenCV】OpenCV实战从入门到精通之 -- 离散傅里叶变换相关函数详解
- 数据库备份和恢复秩序的关系(周围环境:Microsoft SQL Server 2008 R2)
- java B2B2C Springboot多租户电子商城系统-Eureka源码解析...
- c语言司机牌照前两位数一样,c语言
- Lightroom:统一照片的曝光度
- 【书影观后感 一】大秦帝国的罗曼蒂克消亡史
- 东南大学计算机学院分数线,2017年东南大学录取分数线
- “三只猫,三分钟,捉三只老鼠,多少只猫,一百分钟,捉一百只老鼠”有感
- 新型冠状病毒的初期症状有哪些?(Java绘图)
- MTK Kernel Log 看电池信息
- 微信小程序web-view的使用教程
- 【整、借、学、变】四字谈起
- 前端八股文面试题集合
- 基于OpenLayer的室内地图前端设计开发
- osg学习(二十八)有关kml和kmz