1. package com.yuque.phil616.processcontrol;
  2. public class ProcessControl {
  3. public static void main(String[] args) {
  4. /**
  5. * there are two kind of way to control process of computer.
  6. * Loops and Branches
  7. * stack statements to run the program properly called order program
  8. * it likes the code below.
  9. * Every statements are usually atom statement.
  10. * they can be function,statements,assignments,and others.
  11. */
  12. int i,j;
  13. i = 10;
  14. j = i;
  15. /**
  16. * Branches can be control by if statements and switch statements.
  17. */
  18. if(i == 1){
  19. j = 1;
  20. }else if(i == 2){
  21. j = 2;
  22. }else{
  23. j = 0;
  24. }
  25. /**
  26. * this kind of branch is the basic statements of program
  27. */
  28. switch (i){
  29. case 1:j = 1;
  30. break;
  31. case 2:j = 2;
  32. default:
  33. }
  34. /**
  35. * switch are also branch key word
  36. */
  37. System.out.print(j);
  38. }
  39. }

循环

  1. package com.yuque.phil616.processcontrol;
  2. public class LOOP {
  3. /**
  4. * a loop is to run same statements for many time
  5. */
  6. int i;
  7. int j;
  8. void whileFuncDemo(){
  9. while(i > 0){
  10. j++;
  11. }
  12. /**
  13. * this is a basic loop structure,
  14. * as long as i bigger than 0,the statements will be execute repeatedly.
  15. */
  16. for(int c = 0;c < 10;c++){
  17. j++;
  18. }
  19. /**
  20. * there are three parameter in for loop,
  21. * when we execute this loop, the first parameter will be execute.
  22. * it call the initialize factor.
  23. * and to judge the conditions,and run the statements,
  24. * when the statements run completed, run the counter which is the third parameter.
  25. */
  26. /**
  27. * java provide a special loop form called do-while,
  28. * in face do-while struct are exits in ANSI C.
  29. * do-while struct will run the statements once and then judge the condition.
  30. * so we have a special usage in this way.
  31. */
  32. /**
  33. * in some of situation, a block of statements are needed to run once and they are exits
  34. * only they are running,which means their life circle are one.
  35. * but we don't have to form a functions, just a do while which condition statements are false.
  36. */
  37. do{
  38. int a = 1;
  39. int b = 2;
  40. int c = a + b;
  41. }while(false);
  42. }
  43. }