Home Interview Questions and AnswersTechnical Interview Questions and Answers.NET .Net Programming Concepts Interview Questions and Answers for Freshers and Experience Part-4

.net19. Give the syntax of using the for loop in C# code?
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.

You may also like

Leave a Comment