r3 - 07 Nov 2007 - 13:43:06 - WhaleForestYou are here: TWiki >  Processing Web > ProcessingHandbookChinese > Structure1CodeElementsExpressionsStatements

Expressions Statements 表达式,声明

表达式是符号与运算符的组合,一般包括+,*和/这些运算符并对左右的数值进行运算,表达式可以是一个单独数字也可以是多个元素的组合。An expression always has a value, determined by evaluating its contents.

Expression   Value 
 5   5 
 122.3+3.1   125.4 
 ((3+2)*-10) + 1 -49
    

程序分解

每个程序都由不同的代码构成,它们组合起来表达程序师的意图并由电脑编译出结果。在第176页将对更复杂的程序作出分解介绍。

表达式还可以使用>(大于号)和<(小于号)比较两个数值,并得出true或false的结果。

Expression    Value 
 6 > 3   true 
 54 < 50   false
    

当一段句子完结时需要加上结束符号,程序依然,在Processing语言中用分号来做结束符号。 声明有各种不同的用法,可以定义变量,给变量赋值,运行函数,或者创建对象。这些将在稍候做详细探讨,但首先请看以下例子。

size(200,200);  //运行size()函数
int x;  //创建新的变量 x
x=102;  //把值102赋予变量 x
background(x);  //运行background()函数
    
1-03

忘记在声明的最后添加分号是一个很常见的错误,程序将因此无法运行,但会在纠错窗口提醒用户做出更改。

Edit | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r3 < r2 < r1 | More topic actions
 
Powered by TWiki
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback