Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

continue: practical reference

continue: practical reference: continue skips the rest of the current iteration and proceeds to the next.

Version: C# language and .NET 10 reference runtime

Syntax

continue /* grammar-specific form */

continue skips the rest of the current iteration and proceeds to the next.

Use it to reject an element early without extra nesting.

In a for loop the iterator expression still runs; in while the condition is checked immediately.

Inside nesting it affects only the nearest loop; finally still runs.

The complete program actually uses continue; its exact expected stdout is 1,3.

Examples

using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;

var values = new List<int>(); for (var i = 0; i < 5; i++) { if (i % 2 == 0) continue; values.Add(i); } Console.WriteLine(string.Join(",", values));

Result

1,3

The complete program actually uses `continue`; its exact expected stdout is `1,3`.

Sources