1. while循环 while(循环条件){ (特点为:先判断再执行) 循环操作 } 例题: 计算1+2+3+...+100 int i = 1; int sum = 0; while(i<=100){ sum +=i; i++; } 2. do while循环 do{ (特点为:先执行再判断) 循环操作 }while(循环条件) 例题: 计算1+2+3+...+100 int i =1; int sum = 0; do{ sum…
int n = 0; ; ) {//n必须小于100,如果等于100则会再进来进行一次运算,变为101. //因为下面的语句中用到了continue,状态改变n++不能用到最后 n++; ) { m = m + n; Console.WriteLine("到"+n+"层时的分数"+m); } && n <= ) { ) { m += ;//赋值运算符+=,m=m+100 Console.WriteLine("到50层时分数"…
#include <stdio.h> int main(int argc, char **argv) { //定义两个变量 x 跟 n,n的初始化为0: int x; int n=0; //输入x的值: scanf("%d",&x); //开始循环 每一轮x都要被处以10 n加上1,先开始执行循环体的 然后看条件 条件不满足跳出循环 条件满足重新回去循环; do { x/=10; n ++; }while(x>0)…
总结: 1.定义数组并赋值: var arr=[1,2,3,4]; 2.通过下标访问数组: var str=arr[0]; 3.自定义数组 var arr=new Array(); 4.数组的赋值 arr[0]=1; arr[1]="a"; 5.获取数组长度:数组名.length; var len=arr.length; 6.方法带(),属性不带() 7.访问二维数组: var arr2=[[1,2,3,4,],["a","b","c&…
while循环的语法: while 条件测试 do 命令区域 done 举例: #!/bin/bash declare -i i=1 declare -i sum=0 while ((i<=10)) do let sum+=i let ++i done echo $sum 使用while, 读取文件内容 while循环,经典的用法是搭配转向输入,读取文件的内容,做法如下: #!/bin/bash while read line do echo $line done < cvsfile…
本章问题 1.在你的系统中,你能够声明的静态数组最大的长度能达到多少?使用动态内存分配,你最大能获取的内存块有多少? answer: This will vary from system to system,there are several things that may affect the result on PC-based systems,including the memory model in use,the amount of space in the data and/or s…
前言: 节主要是给出BST,AVL和红黑树的C++代码,方便自己以后的查阅,其代码依旧是data structures and algorithm analysis in c++ (second edition)一书的作者所给,关于这3中二叉树在前面的博文算法设计和数据结构学习_4(<数据结构和问题求解>part4笔记)中已经有所介绍.这里不会去详细介绍它们的实现和规则,一是因为这方面的介绍性资料超非常多,另外这3种树的难点都在插入和删除部分,其规则本身并不多,但是要用文字和图形解释其实还蛮耗…
python的控制语句分为: if: if condition: cmd elif condition:#该块为可选 cmd else:#该块为可选 cmd while: whlie condition: cmd else: #该块通常用户whlie退出时,但是通常被省略. cmd for: for i in [1,2,3,4]: print i, 其中当while和for的cmd中包含了break时,则直接跳出循环. 例如 for i in [1,2,3,4]: if i >= 3: brea…
博客园 :梦工厂2012 本月由于事情太多,没能有太多的时间去写博客.不过还好在月底抽时间写了这个多线程网络通信的程序 .程序说明:控制端 创建一个写线程threadWrite和一个读线程threadRead ,写线程用于向控制端发送操控指令.读线程用于读取被控制端姿态数据.这里C# 编写了一个模拟被控端ServerConsole .源代码如下, using System; using System.Collections.Generic; using System.Linq; using S…