(8) Control Process
1. Block Scope
Public static void main (string [] ARGs)
{
Int N;
...
{
Int K;
...
} // K is only defined up to here
}
Public static void main (string [] ARGs)
{
Int N;
...
{
Int K;
Int N; // error -- can't redefine N in inner Block
...
}
}
2. conditional statements
If (condition) Statement
3. Loop
Initialization;
While (loopcontinuationcondition ){
Statement;
Increment;
}
4. Determine the cycle
For (initialization; loopcontinuationcondition; increment) statement;
5. Multiple options -- switch statement
I believe you are familiar with it. Here, we need to note that you cannot use string, but you can only use integer.
String input = ...;
Switch (input) // Error
{
Case "A": // Error
...
Break;
...
}
6. interrupt control flow statements
Break;
Jump out to the outside of the control block;
Break label;
You can jump to the tag location, but the tag must be placed before the outermost loop.
Add a colon to the label.
Continue;
Jump out of the control block;
Continue label;
You can jump to the loop that matches the tag.
Add a colon to the label.