Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to analyze for statements

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

How to analyze for sentences, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

For statement

The general form of a for loop statement is as follows:

For (expression 1; expression 2; expression 3)

Statement

When using the for statement, you need to be aware of the following issues:

(1) the body of the loop can only contain one statement, and a compound statement is used when multiple statements are needed.

(2) the three expressions in the parentheses of the for loop statement are separated by semicolons, and expression 1 is executed only once, which is generally used to initialize the whole loop before the start of the loop. The common use is to initialize the loop control variable; the value of expression 2 determines whether the loop continues to execute, which is the loop control condition. Expression 3 is evaluated after each execution of the loop body, and the common usage is to modify the value of the loop control variable.

(3) the execution process of for statement is to judge the loop condition first, and then execute the loop body, so it is possible that the loop body will not be executed once.

(4) all three expressions in the for statement can be omitted, but the semicolon as a delimiter cannot be omitted. When expression 1 is omitted, the corresponding initialization work can be completed in front of the loop statement; if expression 3 is omitted, the corresponding work can be placed at the end of the loop body; when expression 2 is omitted, the loop condition of the for loop statement defaults to non-0, that is, the loop condition is always true.

Give an example

Example: programming for 1 + 2 + 3 +. A value of + 100, using the for statement.

Reference answer:

1#include

2 int main ()

3 {

4 int i, sum=0

5 for

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 210

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report