if(true) - page 4

 
Nikolai Semko:

You can't build a perpetual loop on if(true). And while(true) is a different story, which I actively use. More precisely, I prefer for(;;) because of shorter notation.

Since you prefer for, this is exactly your story.

 
Алексей Тарабанов:

Untrained.

The compilers nowadays are very clever.

 
Roman:

Thebooltype is intended to store boolean valuestrue orfalse, which have a numeric representation of 1 or 0.
Machine code consists of 1 and 0
1 true
0 false
The bool logical type, is a wrapper over an integer type.

Not exactly.

For non-bool types false only if the value is zero. In all other cases it is true.

I.e., it doesn't have to be just 1. Any value other than zero can be true .

 
Artyom Trishkin:

No, it is not.

false only if the value is zero. In all other cases it is true.

That is, it doesn't have to be only 1. Any value other than zero can be true .

Yes, absolutely right. Didn't comment further on the help.
1 and 0 was for comparison with machine code, for understanding.

 
Artyom Trishkin:

Not exactly.

For non-bool types false only if the value is zero. In all other cases it is true.

I.e. it doesn't have to be only 1. Any value other than zero can be true .

Just for reference:
By the way, there is no bool type in C. It just uses int or char, where 0 is false and the rest is true.

But in Java, the if(1) or if(0) variant won't work, since only the boolean type is needed.

 
Nikolai Semko:

Just for reference:
By the way, there is no bool type in C. It just uses int or char, where 0 is false and the rest is true.

In Java, if(1) or if(0) will not work, because only boolean type is needed.

The C language is long gone, C++ definitely had a boolean

 
Igor Makanu:

The C language has not existed for a long time, C++ definitely had a bool

That's where you're powerfully wrong, Igor.
https://www.tiobe.com/tiobe-index/
A lot of C programmers are needed, more than C++


 
Dmitry Fedoseev:

The compilers are very clever these days.

And you and I seem to be doing okay so far.

 
Igor Makanu:

The C language has not existed for a long time, C++ definitely had a bool

I write dlls in C.)
C is used to write drivers, all sorts of controllers in electronics.

 
Nikolai Semko:

Here you are powerfully wrong.
https://www.tiobe.com/tiobe-index/
A lot of C programmers are needed, more than C++


Well not entirely wrong, C-like languages do exist, but they are tied to specific compilers, mostly compilers that come with controllers

but I'm a fan of Microsoft software, if they have a bool then it's therehttps://docs.microsoft.com/ru-ru/cpp/cpp/bool-cpp?view=vs-2019

SZZ: google found C bool

typedef enum { false, true } bool;

well, at least such a bool exists ))))

Reason: