1

Is there a C or C++ equivalent to 'pass' in python? Also the same with break. For example:

while True:
    if x == 1:
        break
    else:
        pass

But in C/C++ instead?

Gurnoor
  • 133
  • 2
  • 7

1 Answers1

6

Is there a C or C++ equivalent to 'pass' in python?

Yes. There are actually two equivalents. One is the null statement:

;

Another is the empty block statement:

{}

These are in most cases inter-changeable except the null statement cannot be used in all cases where the empty block statement can. For example, the function body must be a block statement.


In the example case, you can omit the else-statement entirely just like you can in Python.

eerorika
  • 232,697
  • 12
  • 197
  • 326
  • 1
    As a code reviewer I would say that if you do use the empty statement in C++ you are expected to note it is deliberately empty. `{/* deliberately empty */}` otherwise people get confused. – Martin York Nov 13 '20 at 03:55