Have you heard about "down-to" operator? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

Have you heard about "down-to" operator?

Let's make it interesting! Suppose you're given a program to print all numbers from m to n. Easy, isn't it? Check out the following code which uses the "down-to" operator for this purpose: https://code.sololearn.com/c9iEFTCXyooP/#cpp But, there is something "irony" in this "down-to" operator... Can you resolve it?

27th Nov 2018, 5:24 AM
777
777 - avatar
15 Answers
+ 12
(a --> 1) means ((a--) > 1) LOL!
27th Nov 2018, 6:53 AM
Babak
Babak - avatar
+ 6
Hey @C++ Soldier (Babak) Nice! You found the "irony" ;)
27th Nov 2018, 7:10 AM
777
777 - avatar
+ 6
@rv7 I thought you were using mobile app too, it's fine though, still waiting for the next prank :D
28th Nov 2018, 5:32 PM
Ipang
+ 5
I had no idea that existed,New trick acquired...thanks for uploading
27th Nov 2018, 6:23 AM
Mensch
Mensch - avatar
+ 5
@Sai welcome! Even I myself had no idea. Actually, it's not just in C++ only, it's also in Java, JS and other popular languages, EXCEPT Python... Can you guess why?
27th Nov 2018, 6:48 AM
777
777 - avatar
+ 5
😀Good joke. The irony is this "operator" actually down-to to 0, not 1
27th Nov 2018, 6:57 AM
Javier Felipe Toribio
Javier Felipe Toribio - avatar
+ 5
@Sai Actually the "-->" thing isn't actually an operator. It's a combo of "--" and ">". Line 8th in my code can be illustrated as: } while ( (a--) > 1 ); And, the loop will runs until a equals 1, i.e., "a goes to 1" ;) This is the reason why there is no docs on this operator in any language. LOL!
27th Nov 2018, 7:15 AM
777
777 - avatar
+ 5
@KrOW how about x ++< 10, "upto" operator?
27th Nov 2018, 7:34 AM
777
777 - avatar
+ 5
rv7 This is less funny 😀😀😀
27th Nov 2018, 7:43 AM
KrOW
KrOW - avatar
+ 5
I'll be waiting for your next prank, but please, next time do it right in a feed post ... LOL, nice one ... XD
27th Nov 2018, 1:14 PM
Ipang
+ 4
Nice meta-operator 😁😁😁😁
27th Nov 2018, 7:06 AM
KrOW
KrOW - avatar
+ 4
@Ipang Thanks! And you're right about the feeds, and I believe you can understand the condition of www.sololearn.com. No feed to feed ;)
28th Nov 2018, 5:25 PM
777
777 - avatar
+ 4
@Ipang Glad to know that. Cheers!
28th Nov 2018, 5:40 PM
777
777 - avatar
+ 3
I can't say,care to enlighten me rv7
27th Nov 2018, 6:55 AM
Mensch
Mensch - avatar
+ 1
I am heard downto() function in kotlin for loop for ( a in 10.downTo(1)) I think this is vaid then the look will the Ranges 10 ..1
1st Jan 2019, 10:55 AM
Santhosh Kumar
Santhosh Kumar - avatar