coursera《计算机程式设计》学习笔记2
2014-09-18 19:41
141 查看
week2
1. if then
if (condition)<span style="font-family: Arial, Helvetica, sans-serif;">{</span>
statement1;
statement2;
statement3;
}
2. if then else
<pre name="code" class="html">if(condition)
statement1;
else
statement2;
3. else if
if (condition1)
statement1;
else if (condition2)
statement2;
else
statement3;
4. 判断式值
(condition) ? expression1 : expression2
5. swith判断
swith(flag) {
case 1:
statement1;
break;
case 2:
statement2;
break;
. . .
case n:
statementn;
break;
default:
default_statement;
}flag必须是变数,而非算式。
case之后必须是常熟,而非算式。
break不可省。
当执行完对应的statement之后必须跳出switch。
为了程式的正确性,必须在每个switch加上default用以处理例外的情况。
6. while回圈
while (condition)
statement;
7. for 回圈
for (initialization; condition; adjustment)
statement;
8. 判断正整数n是否为质数的方法
试着用2到根号n去除n,如果余数为0,则设定 j 为1;如果 j 始终为0,则 n 为质数。
j 作为一个旗标。
9. do while 回圈
do
statement;
while (condition);do while 至少会执行一次
10. break
跳出回圈
continue
跳过回圈剩下的部分,继续新的回圈
1. if then
if (condition)<span style="font-family: Arial, Helvetica, sans-serif;">{</span>
statement1;
statement2;
statement3;
}
2. if then else
<pre name="code" class="html">if(condition)
statement1;
else
statement2;
3. else if
if (condition1)
statement1;
else if (condition2)
statement2;
else
statement3;
4. 判断式值
(condition) ? expression1 : expression2
5. swith判断
swith(flag) {
case 1:
statement1;
break;
case 2:
statement2;
break;
. . .
case n:
statementn;
break;
default:
default_statement;
}flag必须是变数,而非算式。
case之后必须是常熟,而非算式。
break不可省。
当执行完对应的statement之后必须跳出switch。
为了程式的正确性,必须在每个switch加上default用以处理例外的情况。
6. while回圈
while (condition)
statement;
while (condition){ statement1; statement2; statement3; }
7. for 回圈
for (initialization; condition; adjustment)
statement;
8. 判断正整数n是否为质数的方法
试着用2到根号n去除n,如果余数为0,则设定 j 为1;如果 j 始终为0,则 n 为质数。
j 作为一个旗标。
9. do while 回圈
do
statement;
while (condition);do while 至少会执行一次
10. break
跳出回圈
continue
跳过回圈剩下的部分,继续新的回圈
相关文章推荐
- coursera《计算机程式设计》学习笔记6
- coursera《计算机程式设计》学习笔记1
- Coursera课程《Machine Learning》学习笔记(week2)
- Coursera课程《Machine Learning》学习笔记(week1)
- Coursera课程《Machine Learning》学习笔记(week1)
- 《Linux高性能服务器编程》学习笔记——第五章 Linux网络编程基础API(1)
- python3.5《机器学习实战》学习笔记(四):决策树算法
- 继承类的练习 学习笔记
- 《maven实战》学习笔记3——maven使用入门
- 《敏捷软件开发》学习笔记(三)
- python学习笔记(三)
- 《编程之美》学习笔记——2.19区间重合判断
- 周志华《Machine Learning》学习笔记(14)--计算学习理论
- 学习笔记6-Android查看应用输出的错误信息 如何部署应用到真实手机 发布软件
- Vue、Angular和React(学习笔记⑤)
- C++/C学习笔记--(8)
- 《设计模式》学习笔记0——说明
- 《第一行代码-Android》学习笔记(十四)
- 《零基础入门学习Python》学习笔记2
- Coursera-Machine Learning 之 Logistic Regression (逻辑回归)-0x02