Câu hỏi phỏng vấn C#
Câu hỏi

What is the difference between continue and break statements in C#?

Câu trả lời

Here is the difference between the continue and break statements in C#:

continue Statement

  • The continue statement is used to skip the current iteration of a loop and move on to the next iteration.
  • When the continue statement is encountered inside a loop, the code block following it is skipped, and the loop moves on to the next iteration.
  • The continue statement is useful when you want to skip certain iterations based on a specific condition, without terminating the entire loop.
  • Example:
for (int i = 1; i <= 10; i++)
{
    if (i % 2 == 0)
    {
        continue; // Skips even numbers
    }
    Console.WriteLine(i); // Prints only odd numbers
}

break Statement

  • The break statement is used to terminate a loop prematurely, regardless of whether the loop condit...
entry

entry

Gợi ý câu hỏi phỏng vấn

middle

What is difference between constant and readonly ?

expert

Explain what is Weak Reference in C#?

middle

What is the difference between Equality Operator ( == ) and Equals() Method in C#?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào