Learning notes 4 Loop Structure

Source: Internet
Author: User

<A href = "http://net.itheima.com/" target = "blank"> Windows Phone 7 </a>, <a href = "http://net.itheima.com/" target = "blank">. net training </a>. We are looking forward to communicating with you!

 

1. While loop structure:
For example, int I = 0; // I is a cyclic variable.
While (I <5)
{
Execute the statement;
I ++;
}
While loop Syntax:
While (loop condition)
{
Loop body (n programs to be executed cyclically; generally contains I ++ ;)
}
Execution Process:
1) first judge the cycle condition. If the condition is true, turn to 2). If the condition is false, turn to 3)
2) execute the loop body. After the loop body is executed, turn to 1)
3) jump out of the loop and the loop ends.
Note: In the loop body, if the condition is true, it is switched to 2). If the condition is false, it is switched to 3 ).
Features: First Judge and recycle.
2. Do
{Loop body ;}
While (condition );
Execution Process: 1. execution cycle body
2. Determine whether the condition is true. If the condition is true, it is switched to 1. If the condition is false, it is switched to 3.
3. jump out of the loop and the loop ends.
Feature: Execute the command first and then judge.
Note: If the loop condition is not true at the beginning, for the while loop, it will not be executed at once, for the do0-while, It will be executed once.
3. Check for exceptions:
Try // Detection
{
Code to be detected
}
Catch
{
Error message;
}
If the code in try is not abnormal, the code in catch will not be executed.
If the code in try has an exception, the code in catch will be executed.
4. Note that loop and try-catch nesting can solve many bugs.
5. Set the yellow line of code for disconnection. The Code will be executed, but it has not yet been executed.
6. For Loop;
Syntax:
For (expression 1; expression 3)
{
Loop body
}
Execution Process:
Step 1: Calculate expression 1 and move to step 2;
Step 2: Calculate expression 2 (Cyclic condition). If expression 2 is set to true, go to step 3. If expression 2 is set to false, go to step 2.
Step 3: Execute expression 3 and move to Step 3
Step 4; execute expression 2, move to step 2
Step 5: exit the loop.
7. Break:
1 ). Can be used to jump out of the switch-case judgment, used to jump out of the switch
2) used in a loop to immediately exit (terminate) the loop.
Note: When used in a loop, the loop where the break is located exists.
8. bool flag = false, flag
9. continue;
In a loop, once the program executes the continue statement, it immediately ends the loop (that is, it no longer executes the statements below the continue in the loop body) and runs the next loop directly. (Do-while/While directly determines the next cycle condition. If the condition is true, it enters the loop again. For a for loop, execute expression 3 first, and then judge whether the loop condition is successful !)
10. Ternary expressions;
Type 1? Type 2: Type 3
Int max = A> B? A: B;
Console. writeline (max );
Console. readkey ();

*
***
*****
*******
Use C # To program and output the "**********", and learn the "loop" section by yourself, such as multiplication tables and simple cyclic queries.
* ****** The problem can be solved, but the input of this image is still a bit tricky.
***
*

 

Password cracking: http://howsecureismypassword.net/

<A href = "http://net.itheima.com/" target = "blank"> Windows Phone 7 </a>, <a href = "http://net.itheima.com/" target = "blank">. net training </a>. We are looking forward to communicating with you!

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.