0

I have just started learning python, so it may seem a foolish question but i really want to know what could be the real possibility of not using the while true for the python interpreter which Execute compiled code with the help of ceval.c instead of for (;;) here in the same code.

I know the interpreter must go in infinite loop until something is returned hence the infinite for loop was written like this

 for (;;) {
#ifdef WITH_TSC
        if (inst1 == 0) {  

But going by the python own Principle Readability counts won't while true would have been a better option ?

Or this will have any performance difference ?

Bakuriu
  • 98,325
  • 22
  • 197
  • 231
Ankur Anand
  • 3,873
  • 2
  • 23
  • 44
  • 1
    C didn't have `true`; it'd be `while (1)`. Back in the days `for (;;)` could have been faster and it has stuck. [Related](http://stackoverflow.com/questions/885908/while-1-vs-for-is-there-a-speed-difference) – Antti Haapala -- Слава Україні Mar 05 '16 at 19:28
  • @AnttiHaapala [while (1) Vs. for (;;) Is there a speed difference?](http://stackoverflow.com/a/887298/4532996) would seem to say... no, there isn't – cat Mar 05 '16 at 21:08

1 Answers1

1
for (;;) {

is the classical way to make a C forever loop, stemming from the 1970's. I believe it's even in the original Kernighan and Ritchie book. It's idiomatic and a habit, there's no performance reason.

But strange enough most C programmers from that time would have written

if (!inst1) {

rather than

if (inst1 == 0) {

which makes this code a bit inconsistent stylewise...

Jacques de Hooge
  • 6,750
  • 2
  • 28
  • 45