Help understanding a piece of code

Hi guys,

So I was looking up code for a Vignere Cipher and I found this:

http://www.sysnative.com/forums/programming/7366-vigenere-cipher-encode-decode-methods.html

I'm not very experienced in programming so I had some trouble understanding some parts of this code.

If someone could explain what this line of code does in simpler terms that would be very helpful.

j = j + 1 == key.length() ? 0 : j + 1;

Thanks

Also that above code is not mine and I don't intend on using it, I just need clarification for my understanding.

It's an alternative if statement.

So basically, it means this:

1
2
3
4
5
if (j+1 == key.length()){
    j=0;
}
    else
          j=j+1;
Last edited on
Thank you, that was very helpful.
Please do not delete your posts. It prevents other users with similar problems from getting help.

Original post:
phocus wrote:
Hi guys,

So I was looking up code for a Vignere Cipher and I found this:

http://www.sysnative.com/forums/programming/7366-vigenere-cipher-encode-decode-methods.html

I'm not very experienced in programming so I had some trouble understanding some parts of this code.

If someone could explain what this line of code does in simpler terms that would be very helpful.

j = j + 1 == key.length() ? 0 : j + 1;

Thanks

Also that above code is not mine and I don't intend on using it, I just need clarification for my understanding.
http://webcache.googleusercontent.com/search?q=cache:http://www.cplusplus.com/forum/beginner/126072/
Topic archived. No new replies allowed.