# Help with the output.

#### Zns

Hello, I can't find out why the output is the one in the picture, I can't understand the "k%4" condition

#### Attachments

• 1.PNG
27.5 KB · Views: 20

#### WhiteCube

K%4 is not a logical expression. % is the modulo operator. In this case it returns 0, 1, 2, or 3 depending on the value of K.

My guess is, C is treating 0 as false, and non zero as true.

The inner loop prints world when K is 150 (150%4=2), when K is 125 (125%4=1), and stops when K is 100 (100%4=0)

This is poor programming style. Just my opinion.

Zns

#### Zns

K%4 is not a logical expression. % is the modulo operator. In this case it returns 0, 1, 2, or 3 depending on the value of K.

My guess is, C is treating 0 as false, and non zero as true.

The inner loop prints world when K is 150 (150%4=2), when K is 125 (125%4=1), and stops when K is 100 (100%4=0)

This is poor programming style. Just my opinion.
Thank you for the reply.

#### WhiteCube

On the other hand, I would have no gripe with...

`for(j=0;0<(k%4);j++)`

That would be fine.

The reason I used the words "my guess is" was because the last time I used a C compiler, it didn't support a `-=` operator, so I can't make assumptions.

Speaking of true and false values, some programmers define them as constants at the start of their programs. That would make it easier to translate a program into another language. But then they use numeric literals elsewhere in their code, which makes the logical constants kind of pointless.

Perhaps its not about portability, I could be wrong.

#### Infinityhost

k%4 isn't rest from dividing k/4

ie.

k = 9;
k%4 = 1

?

## Ask a Question

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

### Members online

No members online now.