20150727 Day05 Course--while,do-while,for cycle of cyclic structure

Source: Internet
Author: User

20150727 Day05 Course- the while of circular structure, do-while,for cycle

Today is the fifth day of the Java Foundation course, with the following topics:

01.while Cycle

while ( condition ) {

Loop Body

}

Note: All loops must have four elements

Initial Variables

The condition of the cycle .

The body of the loop .

the value of the iteration variable must be changed

Are you qualified?

String userinput= "n";

while (!userinput.equals ("Y")) {

If the user is not entering y, then the loop body is executed

Morning reading materials, PM code

Are you qualified ?

}

Program Debugging--Breakpoint debugging steps:

Set breakpoints

Start debugging

Single-Step: After debugging started, run to set breakpoints to stop the code line, click F6 can step to run the program, observe the program running process

Watch variables: You can see the current value of a variable in the variables view in a single-step run

Problem found: Fix code, rerun, fix problem

The purpose of the program debugging: to identify the cause of defects, correcting defects

The main methods of program debugging: Setting breakpoints, stepping, observing variables

03.do-while Loop -Scenario: Solving a situation where you need to perform the re-judgment first

do{

Loop Body

}while ( cyclic conditions );

when do I use the for loop structure? We prefer the For loop when the number of loops is fixed

A. for ( initial variable ; Cycle Conditions ; Iteration Variables ){

Loop Body

}

It is recommended that when you write a topic that has multiple initial variables, you do not get an out-of-loop definition until you define the data type to the first semicolon, because this can produce an error

The dead loop : If a loop does not have a termination condition, then the program will be executed indefinitely until we forcibly terminate the program and the program is forced to quit, so this loop, called the Dead loop. In the process of writing our program, we must avoid the cycle of death.

08.break; when we want to terminate the execution of the entire loop during the loop, then we can consider using the Break keyword, Break keyword general and logical decision statements if With .

09.continue usage : End the loop and continue to the next loop break: Jump out of the current loop {}

Summary of the circular structure

Difference 1: Syntax

while ( condition ) {

Loop Body

}

do{

Loop Body

}while ( cyclic conditions );

For ( initial variable ; Cycle Conditions ; Iteration Variables ){

Loop Body

}

Difference 2: Execution order

While loop: First judge, then execute

Do-while Cycle: Execute first, then Judge

for Loop: First judge, then execute

Difference 3: Where applicable

When the number of cycles is determined, the for loop is usually selected

When the number of cycles is uncertain, a while or a do-while loop is usually selected

20150727 Day05 Course--while,do-while,for cycle of cyclic structure

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.