This is the 5th day of my participation in the August More Text Challenge

The flow chart

A standard set of graphics used to describe the logic of a program. Usually used to analyze the flow chart of a program. The main flow chart is as follows:

Beginning or end

Graph TD id1(start/End) ID2 (start/end) ID5 (Start/end)

Used to indicate the beginning and end of a process. Rectangles, ellipses, or circles with rounded corners are used to indicate the beginning and end of a process

judge

Graph TD id4{judge}

The diamond represents a judgment, used to indicate whether the operation

Steps in a process

Graph TD ID3 [Steps in the Process]

Use rectangles to represent steps in the process

Input or output

Graph TD id1[input/output /] id2[/ input/output /] id3[input/output]

Use parallelograms or rectangles to represent inputs or outputs in the process

cable

Graph LR A - - > | wire | B

The connection line represents the direction of the two processes

If judgment

Usage:

If false, undefined, null, 0 is false, all others are true

if(conditions1) {// If condition 1 is true, execute the code block below
}else if(conditions2) {// If condition 2 is true, execute the code block below}... You can write an infinite number of EsLesif

else{
 // If none of the above conditions are met, execute this code block
}
Copy the code

details

  1. If a condition is met, the byte ignores all subsequent conditions
  2. Else if is greater than or equal to zero
  3. Else can have 1 or 0
  4. Else can be wrapped or not wrapped
  5. If the code block contains only one line of statements, you can omit the braces

The switch switch

Usage:

switch(expression){casedata1: code block;break;
    casedata2: code block; barak;/ /...
     default: code block barak; }Copy the code

Calculate the return value of the expression, run the data after the case in turn for strict equality to do comparison, as long as there is a place to meet the conditions will be executed after all the code, break out of the loop, will not run other statements.

cycle

Loop structure is a kind of flow control that is used to execute code repeatedly. There are while loops, do-while loops, for loops and so on

Here we make a 1 + 2 +… Plus 100 cases

The while loop

while(conditions) {// Code block, loop body
}
Copy the code
Graph LR started (start)) - >} {condition condition - true - > code block code block > conditions - false -- -- > end ((end))
var sum = 0, i = 1;
while(i<=100){
    sum += i;
    i ++;
}

console.log('Whole loop, 1+2 +... Plus 100 is equal to prime., sum)
Copy the code

In an infinite loop, when the condition is always met, the code breaks out of the loop and executes the loop until it runs out of memory. Browser freezes

The do while loop

usage

do{loop body}while(conditions)Copy the code
Graph LR started (start)) -- -- > code block code block >} {condition condition - true - > code block - false end -- > ((end))
var sum = 0, i = 1;
do{
    sum += i;
    i++
}while(i <= 100)

console.log('do-whole loop, 1+2 +... Plus 100 is equal to prime., sum)
Copy the code

A do-while loop will run through the body of the loop and then condition it. A while loop will not run through the body of the loop

The for loop

usage

forInitialize the expression; Conditions; Conditional change expression){code block}Copy the code
Graph LR Start ((start))--> Initialize expression Initialize expression --> Condition {condition} condition --true--> loop body --> Condition change expression Condition change expression --> Condition --false --> End ((end))
var sum = 0;
for(var i = 1; i <= 100; i ++){
    sum += i;
}
console.log('For loop 1+2 +... Plus 100 is equal to prime., sum)
Copy the code

Loop keyword

  • Break; Jump out of the loop
  • continue; Stop the current loop and enter the next loop
  • retuurn; Terminate the loop

For, forEach, for in, for of