블로그 이미지
Leeway is... the freedom that someone has to take the action they want to or to change their plans.
maetel

Notice

Recent Post

Recent Comment

Recent Trackback

Archive

calendar

1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
  • total
  • today
  • yesterday

Category


for statement

to execute a block of  code for a specified number of times

for (initial-statement; condition; iteration-statement)
    body-statement;

equivalent to:
initial-statement;
while (condition) {
    body-statement;
    iteration-statement;
}


control variable
wikipedia: In programming, a control variable is a program variable that is used to regulate the flow of control of the program. For example, a loop control variable is used to regulate the number of times the body of a program loop is executed; it is incremented (or decremented when counting down) each time the loop body is executed.


switch statement

case label
default label

ref.    http://cplusplus.com/doc/tutorial/control.html
Its objective is to check several possible constant values for an expression. Something similar to what we did at the beginning of this section with the concatenation of several if and else if instructions.

Notice that switch can only be used to compare an expression against constants. Therefore we cannot put variables as labels (for example case n: where n is a variable) or ranges (case (1..3):) because they are not valid C++ constants.

If you need to check ranges or values that are not constants, use a concatenation of if and else if statements.

ref.   http://www.cprogramming.com/reference/switch.html
The braces are always needed following the switch statement. No braces are needed following any case. If the variable is equal to one of the values following a case, then the code following the case is executed. Execution will "fall through" from one case statement to the next, executing all code following the case statement, including code following other case statements and the default statement. The prevent falling through, include break;at the end of any code block. The default case will execute in the case that no other case is true.

ref.   http://www.cprogramming.com/tutorial/lesson5.html
Switch case statements are a substitute for long if statements that compare a variable to several "integral" values ("integral" values are simply values that can be expressed as an integer, such as the value of a char).

An important thing to note about the switch statement is that the case values may only be constant integral expressions.

ref.    http://en.wikipedia.org/wiki/Switch_statement
Its purpose is to allow the value of a variable or expression to control the flow of program execution.

cf. the switch statement in Java
A switch works with the byte, short, char, and int primitive data types. It also works with enumerated types (discussed in Classes and Inheritance) and a few special classes that "wrap" certain primitive types: Character, Byte, Short, and Integer (discussed in Simple Data Objects ).

cf. switch() in Processing
Program controls jumps to the case with the same value as the expression. All remaining statements in the switch are executed unless redirected by a break. Only primitive datatypes which can convert to an integer (byte, char, and int) may be used as the expression parameter. The default is optional.

A break statement inside a switch tells the computer to continue execution after the switch. If a break statement is not there, execution will continue with the next statement.    (121쪽)



switch, break, and continue


'@GSMC > 서용덕: DMD Programming' 카테고리의 다른 글

to calculate the exponent of a power number  (0) 2008.04.16
week 6 review  (0) 2008.04.16
[Steve Oualline] 7. Programming Process  (0) 2008.04.05
week 4 review  (0) 2008.03.27
[Steve Ouallline] 6. Decision and Control Statements  (0) 2008.03.25
posted by maetel