Home »

Give the syntax of using the for loop in C# code?

Question ListCategory: C#.NETGive the syntax of using the for loop in C# code?
milleranthony7 author asked 9 years ago
1 Answers
jessica537 author answered 8 years ago

The syntax of using the for loop in C# code is given as follows: for(initializer; condition; loop expression) { //statements } In the preceding syntax, initializer is the initial value of the variable, condition is the expression that is checked before the execution of the for loop, and loop expression either increments or decrements the loop counter. The example of using the for loop in C# is shown in the following code snippet: for(int i = 0; i < 5; i++) Console.WriteLine("Hello"); In the preceding code snippet, the word Hello will be displayed for five times in the output window.

Please login or Register to Submit Answer