首页 > 科技 > Control Flow and Char type

Control Flow and Char type

2007年8月23日 13点15分 发表评论 阅读评论

Condition branching(or jumping), loop category are both used for controlling flow.

if syntax:
if(expression){
statement1;
statement2;
}

else if(expression){
statement1;
statement2;
}
else{
statement1;
statement2;
}

Here expression is the condition criterion. If the expression is logical TRUE(nonzero), the statements inside the braces, are executed. If the expression is logical FALSE(zero), then the statements are skipped. Note, that the braces form a block of statements that is under the control of the if statement. If there is only one statement inside the block, the braces can be ignored. The parentness, however, must always be used to closed the condition expression. For instance:
if(x>0)
printf(“x>0n”);

The general form of the switch statement is:
switch(expression){
case expression1:
statement1;
break; //break is optional
case expression2:
statement2;
break;
default:
statement-default;
break;
}

When there’s no break, this is important feature of the switch statement. The computer continutes to execute the statements following the selected case until the end of the switch statement. If the return value of expression is equal to the constant expression expression1, the statement statement1 is executed. If however, the value of expression is not equal to any value of the constante expressions labeled by the case word, the statement-default key word is executed.

Add a break statement at the end of the statement list following every case label, if you want to exit the switch constant after the statements within a selected cases are executed.

The continute statement: Instead of breaking loop, there’re timeswhen you want to stay in a loop but skip over some statements within the loop. The continute statement causes execution to jump to the top of the loop immediately. Be aware to use this statement, as well as the break statement, may make your program hard to debug.

Goto is not recommended because it may cause your program to be unreliable and hard to debug.

The char Data Type:
An object of the char data type represents a single character of the character set used by your computer. But a computer can only store numeric code. Therebefor, characters such as A,a,B,b and so on all have a unique numeric code that is used by computers to represent the characters. Usually, a character takes 8 bits to store its numeric code.

For many computers, the ASCII code are the standard codes to represent a character set. ASCII, stands for American Standard Code for Information Interchange). The original ASCII character has set only 128 characters because it was the lower 7 bits that can be represent 2**7(128) characters. On IBM-compatible PCs, the character set is extended to contain a total of 2**8=256 characters.

分类: 科技 标签:
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.
您必须在 登录 后才能发布评论.