1. 首页
  2. 文档
  3. Logical statement

白皮书下载

实在智能Agent产品白皮书(7.2.0).pdf

Logical statement

发刊日期:
2021/10/15

编辑团队:
实在学院

Logical statements describe the logical order of program execution. These include if else, while / for, loop nesting, break, continue, and pass.

1、 If else conditional statement

The code block to be executed is determined by the execution result (true or false) of one or more statements. Specify that any non-0 and non null (null) values are true, 0 or null is false. If statement is used to control program execution. Its basic form is:

If judgment conditions:

     Execute statement……

else:

     Execute statement……

When the "judgment condition" is true (non-zero), the following statements are executed, and the execution content can be multiple lines to narrow in and distinguish the same range. Else is an optional statement. When you need to execute the content when the condition is not true, you can execute the relevant statement.

2、 While / for loop statement

Loop statements allow us to execute a statement or statement group multiple times, including for loops and while loops.

*While loop:While statement is used to execute a program circularly, that is, under certain conditions, execute a certain program circularly to deal with the same tasks that need to be processed repeatedly. Its basic form is:

While judgment condition:

Execute statements……

The execution statement can be a single statement or a block of statements. The judgment condition can be any expression, and any non-zero, or non empty (null) value is true. When the judgment condition is false, the loop ends.

*For loop:The for loop can traverse any sequence of items, such as a list or a string. The syntax format of the for loop is as follows:

for iterating_ var in sequence: statements(s)

*Loop nesting:In fact, rap allows embedding another loop in the body of one loop. Its syntax is:

for iterating_ var in sequence:

   for iterating_ var in sequence:

     statements(s)

statements(s)

3、 Break loop termination

Just like in C language, it breaks the minimum closed for or while loop. The break statement is used to terminate the loop statement, that is, if the loop condition has no false condition or the sequence has not been completely recursive, the execution of the loop statement will also be stopped. Break statements are used in while and for loops. If you use nested loops, the break statement stops executing the deepest loop and starts executing the next line of code.

4、 Continue jump out of loop

 The continue statement jumps out of this loop, and the break statement jumps out of the entire loop. The continue statement is used to skip the remaining statements of the current cycle and then continue to the next cycle. The continue statement is used in while and for loops.

5、 Pass empty statement

Pass is an empty statement to maintain the integrity of the program structure. Pass does nothing. It is generally used as a placeholder statement.

 

企业培训
技术支持
加入社群
公众号
实在智能Agent学习群
扫码关注微信公众号