What is the difference between (;;) and while (1)?

Possible duplicate:
Is "for (;;)" faster than "while (TRUE)"? If not, why do people use it?

I was wondering, what is the difference between for(;;)and while(1)when both perform the same function? Will there be a difference in compilation speed

+3
source share
10 answers

The difference is that many compilers will warn about while(true)("constant expression used as loop expression"), while no one knows about warning about for(;;).

However, they must generate the same code.

+9
source

, .

+8

for :

#define ever (; ;) // note the two happy faces? ;)

for ever { ... }   // endless loop

while.

+8
  • , break .
  • , (1),
+6

. .

+4

6 , 110 .

.

+4

, - , .

for (int i =0; i < 100; i++) {
   // some code
} 
0

Both are the same in C ++. However, your message is marked with c#and c++.

If you use C #, you need to use while (true) {...}. Personally, I prefer the same thing in C ++: numbers are only used when working with ... well, numbers! When working with Boolean values, trueand are used false.

0
source

Both of them define the same functional behavior and produce the exact same IL code from C #.

0
source

I'm an old school, I'm still doing the following:

#define TRUE 1  
#define FALSE 0  
while (TRUE) { /*--do something, mutley--* }
-1
source

Source: https://habr.com/ru/post/1778460/


All Articles