package com.yuque.phil616.processcontrol;
public class ProcessControl {
public static void main(String[] args) {
/**
* there are two kind of way to control process of computer.
* Loops and Branches
* stack statements to run the program properly called order program
* it likes the code below.
* Every statements are usually atom statement.
* they can be function,statements,assignments,and others.
*/
int i,j;
i = 10;
j = i;
/**
* Branches can be control by if statements and switch statements.
*/
if(i == 1){
j = 1;
}else if(i == 2){
j = 2;
}else{
j = 0;
}
/**
* this kind of branch is the basic statements of program
*/
switch (i){
case 1:j = 1;
break;
case 2:j = 2;
default:
}
/**
* switch are also branch key word
*/
System.out.print(j);
}
}
循环
package com.yuque.phil616.processcontrol;
public class LOOP {
/**
* a loop is to run same statements for many time
*/
int i;
int j;
void whileFuncDemo(){
while(i > 0){
j++;
}
/**
* this is a basic loop structure,
* as long as i bigger than 0,the statements will be execute repeatedly.
*/
for(int c = 0;c < 10;c++){
j++;
}
/**
* there are three parameter in for loop,
* when we execute this loop, the first parameter will be execute.
* it call the initialize factor.
* and to judge the conditions,and run the statements,
* when the statements run completed, run the counter which is the third parameter.
*/
/**
* java provide a special loop form called do-while,
* in face do-while struct are exits in ANSI C.
* do-while struct will run the statements once and then judge the condition.
* so we have a special usage in this way.
*/
/**
* in some of situation, a block of statements are needed to run once and they are exits
* only they are running,which means their life circle are one.
* but we don't have to form a functions, just a do while which condition statements are false.
*/
do{
int a = 1;
int b = 2;
int c = a + b;
}while(false);
}
}