How to use the C # while loop statement

Source: Internet
Author: User
Tags foreach

First of all, the difference between foreach and for, foreach is for the object traversal, do not need to define the number of cycles, but there is a disadvantage, the foreach traversal is read-only data, can not be in a Foreach object additions and deletions, and the for loop can be. Your code to change to a while loop is as follows:

The code is as follows Copy Code

int I=0;while (i<ds. table["Userreg"]. Rows.Count) {i++;}

Cases

The code is as follows Copy Code

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;

Namespace Interrupt Loop
{
Class Program
{
static void Main (string[] args)
{
100 or less, seven.
int i = 0;
while (I < 100)
{
i++;
if (i%7==0 | | i%10==7| | I/10==7)
{
Continue
}
Console.WriteLine ("{0}", i);
}
Console.readkey ();
}
}
}

the difference between the Return,continue,break in the while.

Return: Exit main function

Continue: Directly to the next round cycle

Break: Jump right out of the current loop

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.