Get the App
SLTechnology News&Howtos  ›  Development  › 

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

Shulou Source: shulou.com Published: 2022-06-02 02:41:50 10月03日 Update

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

Tags: Loops variables between language content situation times articles differences values examples interests only guys partners universality more knowledge structure scope Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Xiaomi OPPO Reno Huawei Redmi