473,511 Members | 15,624 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What does this statement yield?

I am reading other people's code and come across this statement.
Does it mean phase revolve arround 0,1,2 and 3 & 3 makes 0?

Thank you.
phase = 0;
for (i = 0; i <= 100; i++) {
phase=(phase+1)&3;
}

Jul 29 '05 #1
2 1973
* Frank:
I am reading other people's code and come across this statement.
Does it mean phase revolve arround 0,1,2 and 3 & 3 makes 0?

Thank you.
phase = 0;
for (i = 0; i <= 100; i++) {
phase=(phase+1)&3;
}


For integer types '&3' is effectively the same as '%4'.

I.e. for such types the code should yield 101%4 = 1.

If 'phase' is of a user-defined type then nothing can be said.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 29 '05 #2

"Alf P. Steinbach" <al***@start.no> wrote in message
news:42****************@news.individual.net...
* Frank:
I am reading other people's code and come across this statement.
Does it mean phase revolve arround 0,1,2 and 3 & 3 makes 0?

Thank you.
phase = 0;
for (i = 0; i <= 100; i++) {
phase=(phase+1)&3;
}


For integer types '&3' is effectively the same as '%4'.

I.e. for such types the code should yield 101%4 = 1.

If 'phase' is of a user-defined type then nothing can be said.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


Thank you. Understood.

Jul 29 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

54
6502
by: Brandon J. Van Every | last post by:
I'm realizing I didn't frame my question well. What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump up in your chair and scream "Wow! Ruby has *that*? That is SO...
2
3870
by: Jack | last post by:
Hi, I am trying to check for the final sql statement before passing it to a database. I want to build the statement using user input in three text boxes. However, the sql statement does not give...
5
2236
by: Jerzy Karczmarczuk | last post by:
I thought that the following sequence gl=0 def gen(x): global gl gl=x yield x s=gen(1)
8
3023
by: al3x | last post by:
hi... in c# 2.0 will be possible use a new keywork "yield"... I would like to know if there is an algorithm that implements yield statement in a c# or c++ thanks bye Sandro
2
8718
by: yyhhjj | last post by:
I created a test program to implement an iterator. First, I used 'yield break' in the iterator, it worked normally. Then, I simply used 'break' in the places of 'yield break', it still worked...
669
25400
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
27
5294
by: Steven D'Aprano | last post by:
I thought that an iterator was any object that follows the iterator protocol, that is, it has a next() method and an __iter__() method. But I'm having problems writing a class that acts as an...
6
1520
by: Shriphani | last post by:
Hello all, Let us say I have a function like this: def efficientFiller(file): worthless_list = pot_file = open(file,'r') pot_file_text = pot_file.readlines() for line in pot_file_text: if...
7
1500
by: Alex Bryan | last post by:
Okay, so i don't really understand the Yield thing and i know it is useful. I've read a few things about it but it is all programming jargon and so basically it is hard for me to understand. So can...
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7371
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7432
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7093
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5077
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1583
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.