iOS Development Knowledge (v)

Source: Internet
Author: User

    1. Process Control

    • Sequential structure: The default process structure. Each statement is executed in the written order.

    • Select structure: Judge a given condition and then decide which piece of code to execute based on the result of the decision.

    • Loop structure: Executes a piece of code repeatedly when a given condition is true.



    1. Select Structure-if

    1. Simple to use

    • An if (expression) statement 1;

    • if (count>50) classes; Class


    • An if (expression) statement 1; Else Statement 2;

    • F (count>50) classes; else no classes;


    • if (expression) {}

    • if (count>50) {class, classroom;} else {}

    • Scope of {}


    • If-else If-else

    • if (a==0) else if (a>0) Else

    • Features: Only one parenthesis will be executed


    • Compound condition

    • The value range of class time (9~12 | | 14 ~17)


    • Trap

    • if (a!=0) {A is not 0;} else {A is 0;}

    • if (a); {  }

    • if (a=0)

    • A = = 0;

    • if (ten) int a = 9;


    1. Exercises

    2. Enter an integer day to represent the day of the week, output the corresponding day of the week according to the value of day, such as day==1, to output "Monday"

    3. Enter an integer month to represent the month, according to the month output corresponding to the season.

Spring: 3, 4, 5

Summer: 6, 7, 8

Autumn: 9, 10, 11

Winter: 12, 1, 2

    1. Enter an integer score to represent the score, based on the fractional output level (A-E) (in two ways)

a:90~100

b:80~89

c:70~79

d:60~69

E:0~60


    1. Select Structure-switch

    1. Simple to use

    • switch (expression) {case numeric 1:break; ... default:break;}

    • Example

int a = 10;

Switch (a) {

Case 0:

printf ("This is a 0");

Break

Case 5:

printf ("This is a 5");

Break

Case 10:

printf ("This is a 10");

Break

Default

printf ("nothing");

Break

}

    • Briefly describe the role of break

    • Defining variables in case


    1. Comparison of IF and switch

    • A lot of things are interchangeable.

    • If used more, more flexible, switch can only a single value


    1. Exercises

Use switch instead of if to implement the problem in if


    1. Cyclic structure-while

    1. Simple to use

    • Continuous printf ("push-ups") 20 times;

    • while (expression) {}

    • Continue: Output 5 times take a break.

    • Use of break: Stop a loop at a time

    1. Characteristics

The loop body is executed only if the condition is established.

    1. Exercises

    2. Prompts the user to enter a positive integer n, computes the 1+2+3+...+n and

    3. Prompts the user to enter a positive integer n, computes the 1-2+3-4+5-6+...+n and

    4. Trap

while (condition);


    1. Loop structure-do while

    • Features: Must be executed once the body of the loop

    • While and do While loop comparison

int i=0;
while (i<0) {
i++;
}


int i=0;
do{
i++;
} while (i<0);


    1. Cyclic structure-for

    1. Simple and practical

    • Run process

    • Initialization statements and so on can be multiple sentences (place printf in the for parentheses)


    1. For loop nesting

Friends List 1

Friends 1

Friends 2

Friends List 2

Friends 1

Friends 2

Friends List 3

Friends 1

Friends 2


    1. Trap

    2. Dead loop for (;;);

    3. Scope of internal variables for the for loop body

    4. Scope obfuscation

for (int i = 0; i<5; i++) int a = 10;


    1. Comparison of While loops and for loops

    • Can be interchanged

    • The variables for the for loop can be recovered in time


    1. Exercises

    2. Prompts the user to enter a positive integer n, if N5, outputs the following graph, other n values, and so on

    1. Output 99 multiplication table


    1. Break and Continue

    1. Break

    • Use occasion: switch\ cycle Structure

    • Break under loop nesting


    1. Continue

    • Application: Cyclic structure

    • Continue under cyclic nesting


iOS Development Knowledge (v)

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.