База знанияИзпитен център
BGБългарски
Избери език13

CKTIS / C#

continue: практическа справка

continue: практическа справка: continue пропуска остатъка от текущата итерация и преминава към следващата.

Версия: C# language and .NET 10 reference runtime

Синтаксис

continue /* grammar-specific form */

continue пропуска остатъка от текущата итерация и преминава към следващата.

Използвайте за ранно отхвърляне на елемент без допълнително влагане.

В for iterator expression пак се изпълнява; в while условието се проверява веднага.

При влагане засяга само най-близкия цикъл; finally пак се изпълнява.

Пълната програма действително използва continue; точният очакван stdout е 1,3.

Примери

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));

Резултат

1,3

Пълната програма действително използва `continue`; точният очакван stdout е `1,3`.

Източници