asp.net and do Loop statement usage sharing _ Practical tips

Source: Internet
Author: User
Tags readline
The For loop for this example creates a Mandelbrot image.
Copy Code code as follows:

Using System;
Namespace A
{
Class Program
{
public static void Main (string[] args)
{
Double Realcoord,imagcoord;
Double Realtemp,imagtemp,realtemp2,arg;
int iterations;
for (imagcoord=1.2;imagcoord>=-1.2;imagcoord-=0.05)
{
for (realcoord=-0.6;realcoord<=1.77;realcoord+=0.03)
{
iterations=0;
Realtemp=realcoord;
Imagtemp=imagcoord;
Arg= (Realcoord*realcoord) + (Imagcoord*imagcoord);
while ((arg<4) && (iterations<40))
{
Realtemp2= (realtemp*realtemp)-(imagtemp*imagtemp)-realcoord;
imagtemp= (2*realtemp*imagtemp)-imagcoord;
REALTEMP=REALTEMP2;
Arg= (realtemp*realtemp) + (imagtemp*imagtemp);
Iterations+=1;
}
Switch (iterations% 4)
{
Case 0:
Console.Write (".");
Break
Case 1:
Console.Write ("O");
Break
Case 2:
Console.Write ("0");
Break
Case 3:
Console.Write ("@");
Break
}
}
Console.Write ("n");
}
Console.readkey ();
}
}
}

Do statement of loop structure
The do statement of the loop structure executes the corresponding code according to the test result of the Boolean value, and the DO statement executes at least once.
Copy Code code as follows:

Using System;
Namespace A
{
Class Program
{
public static void Main (string[] args)
{
Double balance,interestrate,targetbalance;
Console.WriteLine ("What is your current balance?");
Balance=convert.todouble (Console.ReadLine ());
Console.WriteLine ("What is your current annual interest rate (in%)");
Interestrate= 1+convert.todouble (Console.ReadLine ())/100.0;
Console.WriteLine ("What balance would you like to have?");
Targetbalance=convert.todouble (Console.ReadLine ());
int totalyears=0;
Todo
{
Balance*=interestrate;
++totalyears;
}
while (balance<targetbalance);
Console.WriteLine ("In {0} year {1}" you ll have a balance of {2}. ", Totalyears,totalyears==1?" ":" S ", BALAN00CE);
Console.readkey ();
}
}
}

Summarize
The DO statement executes at least once at loop time, regardless of whether the condition is set up, and the page for Loop statement does not execute if the condition is not set.
Related Article

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.