tailieunhanh - Lecture Elementary programming with C - Session 6: Loop

After completing this chapter, students will be able to: Understand ‘for’ loop in ‘C’, work with comma operator, understand nested loops, understand the ‘while’ loop and the ‘do-while’ loop, work with break and continue statements, understand the exit() function. | Loop Session 6 Understand ‘for’ loop in ‘C’ Work with comma operator Understand nested loops Understand the ‘while’ loop and the ‘do-while’ loop Work with break and continue statements Understand the exit() function Objectives What is a Loop? Section of code in a program which is executed repeatedly, until a specific condition is satisfied 3 types of Loop Structures The for loop The while loop The do .while loop The for loop-1 Syntax The initialize counter is an assignment statement that sets the loop control variable, before entering the loop The evaluation parameter defines how the loop control variable changes, each time the loop is executed The conditional test is a relational expression, which determines, when the loop will exit The three sections of the for loop must be separated by a semicolon(;) The statement, which forms the body of the loop, can either be a single statement or a compound statement The for loop continues to execute as long as the conditional test evaluates to true. When the condition becomes false, the program resumes on the statement following the for loop The for loop-2 /*This program demonstrates the for loop in a C program */ #include main() { int count; printf(“\tThis is a \n”); for(count = 1; count main() { int i, j , max; printf(“Please enter the maximum value \n”); printf(“for which a table can be printed: “); scanf(“%d”, &max); for(i = 0 , j = max ; i main() { | Loop Session 6 Understand ‘for’ loop in ‘C’ Work with comma operator Understand nested loops Understand the ‘while’ loop and the ‘do-while’ loop Work with break and continue statements Understand the exit() function Objectives What is a Loop? Section of code in a program which is executed repeatedly, until a specific condition is satisfied 3 types of Loop Structures The for loop The while loop The do .while loop The for loop-1 Syntax The initialize counter is an assignment statement that sets the loop control variable, before entering the loop The evaluation parameter defines how the loop control variable changes, each time the loop is executed The conditional test is a relational expression, which determines, when the loop will exit The three sections of the for loop must be separated by a semicolon(;) The statement, which forms the body of the loop, can either be a single statement or a compound statement The for loop continues to execute as long as the conditional test .

TỪ KHÓA LIÊN QUAN