Study day 8

Time:2022-5-6

C language

  1. The general form of the for statement

    1. For — loop structure

    2. for( :)

    3. int a, sum = 0;
      for (a = 1; a <= 100; a++)
      {
      	sum = sum + a;
      }
      printf("sum=%d", sum);
    4. A = 1 in parentheses is the initial value of the cyclic variable, a < = 100 is the condition for the end of the cyclic variable, a + + is the added value of the cyclic variable

    5. The expression is 1, which can be omitted

    6. int a, sum = 0;
      a = 1;// You can assign a value to it first - the same usage as the previous one
      For (; a < = 100; a + +) // must have; If there is no sign, it will fail. It is only to omit expression 1, that is, a = 1
      {
      	sum = sum + a;
      }
      printf("sum=%d", sum);
    7. Expression 2 can also be omitted, but the end of break must be added, otherwise it will loop indefinitely

    8. int a, sum = 0;
      a = 1;
      For (;; a + +) // must have; If no, it will fail
      {
      	sum = sum + a;
      	If (a > = 100) // conditions for ending the loop
      		break;  // The purpose is to end the cycle
      
      }
      printf("sum=%d", sum);
    9. Effect omitted from expression 3

    10. int a, sum;
      
      for (sum = 0,a = 1; a <= 100; )// Must have; If no, it will fail
      {
      sum = sum + a;
      	
      	a++;// Omit expression 3 to ensure that the for loop can end normally
          
      
      }
      printf("sum=%d", sum);
    11. sum = 0,a = 1;

      1. Sum = 0, - comma expression
                	2. sum = 0,a = 1; —— Expression 1. There is a comma expression in expression 1
    12. Expression 1, expression 2 and expression 3 in for can be omitted

  2. For statement actual

  3. Main description of the for statement

Recommended Today

Unified solution for converting code items by spring boot enumeration

Define structure and interface public class CodeItem { private String _itemText; private Object _itemValue; public CodeItem(){ } public CodeItem(String itemText, Object itemValue){ _itemText = itemText; _itemValue = itemValue; } public String get_itemText() { return _itemText; } public void set_itemText(String _itemText) { this._itemText = _itemText; } public Object get_itemValue() { return _itemValue; } public void set_itemValue(Object […]