In C#, I’ve seen some strange and complex logic in the headers of loops.
What is/isn’t possible in the header of a for loop? Is it possible to have more than one incrementor/variable?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, it is possible. That is, this is perfectly legal:
That is exactly what the grammar will tell you. Here is the grammar for a
forstatement in C#:Note that both the
for-initializerand thefor-iteratorallow compound statements viastatement-expression-list. See §8.8.3 of the language specification for addtional details. You’ll probably also want to visit §8.5.1 of the specification for exactly whatlocal-variable-declarationentails (hint:int i = 0, j = n - 1, k = 42is legal butint i = 0, j = n - 1, long k = 42is not).