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

C what are the differences between for, while and do-while loops?

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces the differences between the c language for, while and do-while cycle, the article is very detailed, has a certain reference value, interested friends must read it!

For,while,do-while distinction

Cyclic structure

1. Initialize variables:

Initialization variables defined in for loops can only be used by themselves; while and do-while loops, initialization variables are already outside, so they can also be used outside.

2. Times of execution:

The for loop and the while loop are (judge before execution), but the do-while loop is (execute before judgment).

3. The universality of use is different:

In most cases, the three loops can be switched back and forth. But where the number of times is determined and the scope is determined, the for loop is used.

Detailed examples are as follows:

Programming calculation 1 "2" 3 +. + 100

a. Using for Loop

# include int main () {int iJING summing 0; for (iSome1teri

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: 0

*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

Development

Wechat

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

12
Report