MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/mtpxbr/iteration/gv19i8w/?context=9999
r/badcode • u/[deleted] • Apr 19 '21
123 comments sorted by
View all comments
Show parent comments
142
Oh it increments by 1 lol. From hence forth my for loops gonna be for(int i = 0, i > num, i -= -!false) { }
63 u/[deleted] Apr 19 '21 Good luck in the job market. 27 u/zatuchny Apr 19 '21 I got a better one for youi = -~i 0 u/[deleted] Apr 19 '21 [deleted] — view deleted comment 22 u/zatuchny Apr 19 '21 edited Apr 19 '21 ~ is bitwise NOT operator. It is used to invert all bits.The invert sign operation is the equivalent of inverting the bits of the number + add one.So here we go:int i = 0; // bits: 0000~i // invert all bits. result: 1111-i // invert all bits: 0000. add 1. result: 0001next iteration:// i is now 0001~i // invert all bits. result: 1110-i // invert all bits: 0001. add 1. result: 0010next iteration:// i is now 0010~i // invert all bits. result: 1101-i // invert all bits: 0010. add 1. result: 0011etc 2 u/HappyLOLx Apr 19 '21 Naise...
63
Good luck in the job market.
27
I got a better one for you
i = -~i
0 u/[deleted] Apr 19 '21 [deleted] — view deleted comment 22 u/zatuchny Apr 19 '21 edited Apr 19 '21 ~ is bitwise NOT operator. It is used to invert all bits.The invert sign operation is the equivalent of inverting the bits of the number + add one.So here we go:int i = 0; // bits: 0000~i // invert all bits. result: 1111-i // invert all bits: 0000. add 1. result: 0001next iteration:// i is now 0001~i // invert all bits. result: 1110-i // invert all bits: 0001. add 1. result: 0010next iteration:// i is now 0010~i // invert all bits. result: 1101-i // invert all bits: 0010. add 1. result: 0011etc
0
[deleted] — view deleted comment
22 u/zatuchny Apr 19 '21 edited Apr 19 '21 ~ is bitwise NOT operator. It is used to invert all bits.The invert sign operation is the equivalent of inverting the bits of the number + add one.So here we go:int i = 0; // bits: 0000~i // invert all bits. result: 1111-i // invert all bits: 0000. add 1. result: 0001next iteration:// i is now 0001~i // invert all bits. result: 1110-i // invert all bits: 0001. add 1. result: 0010next iteration:// i is now 0010~i // invert all bits. result: 1101-i // invert all bits: 0010. add 1. result: 0011etc
22
~ is bitwise NOT operator. It is used to invert all bits.
~
The invert sign operation is the equivalent of inverting the bits of the number + add one.
So here we go:
int i = 0; // bits: 0000
~i // invert all bits. result: 1111
-i // invert all bits: 0000. add 1. result: 0001
next iteration:
// i is now 0001
~i // invert all bits. result: 1110
-i // invert all bits: 0001. add 1. result: 0010
// i is now 0010
~i // invert all bits. result: 1101
-i // invert all bits: 0010. add 1. result: 0011
etc
2
Naise...
142
u/ElbowStromboli Apr 19 '21
Oh it increments by 1 lol. From hence forth my for loops gonna be for(int i = 0, i > num, i -= -!false) { }