tailieunhanh - Lecture Introduction to computer and programming - Lecture No 11

This chapter discusses the implementation of dynamic arrays and other objects using conventional techniques for managing heap memory. Especially important in this context is the notion of heap overflow, along with strategies for dealing with heap overflow when it occurs at run time. We discuss three key algorithms for heap memory management, which are affectionately known as garbage collection algorithms. | CSC103: Introduction to Computer and Programming Lecture No 11 Previous lecture for loop break statement continue statement do while loop Today’s lecture outline Example program – nested loop break and continue statement case control structure Example program Write a program to generate all combinations of 1, 2 and 3 using for loop. 1 1 1 1 1 2 1 1 3 1 2 1 1 2 2 1 2 3 1 3 1 1 3 2 1 3 3 i j k 2 1 1 2 1 2 2 1 3 2 2 1 2 2 2 2 2 3 2 3 1 2 3 2 2 3 3 3 1 1 3 1 2 3 1 3 3 2 1 3 2 2 3 2 3 3 3 1 3 3 2 3 3 3 Write a program continue statement break statement Case control structure The control statement that allows us to make a decision from the number of choices is called a switch Sequence of execution First, the integer expression following the keyword switch is evaluated The value it gives is then matched, one by one, against the constant values that follow the case statements When a match is found, the program executes the statements following that case and all subsequent case and default statements as well If no match is found with any of the case statements, only the statements following the default are executed Flowchart – case control structure C code – case control structure switch(2) Cont. Flow chart vs C code Tips and traps case can be used in any order Cont. You are also allowed to use char values in case and switch Cont. At times we may want to execute a common set of statements for multiple cases Go to program Cont. Even if there are multiple statements to be executed in each case there is no need to enclose them within a pair of braces It is possible to have a switch without a default case float is not allowed in case statement . case : Cont. The break statement in a switch takes the control outside the switch However, use of continue will not take the control to the beginning of switch Switch can be nested The switch statement is very useful while writing menu driven programs switch Versus if-else Ladder A float expression cannot be tested using a switch | CSC103: Introduction to Computer and Programming Lecture No 11 Previous lecture for loop break statement continue statement do while loop Today’s lecture outline Example program – nested loop break and continue statement case control structure Example program Write a program to generate all combinations of 1, 2 and 3 using for loop. 1 1 1 1 1 2 1 1 3 1 2 1 1 2 2 1 2 3 1 3 1 1 3 2 1 3 3 i j k 2 1 1 2 1 2 2 1 3 2 2 1 2 2 2 2 2 3 2 3 1 2 3 2 2 3 3 3 1 1 3 1 2 3 1 3 3 2 1 3 2 2 3 2 3 3 3 1 3 3 2 3 3 3 Write a program continue statement break statement Case control structure The control statement that allows us to make a decision from the number of choices is called a switch Sequence of execution First, the integer expression following the keyword switch is evaluated The value it gives is then matched, one by one, against the constant values that follow the case statements When a match is found, the program executes the statements following that case and all subsequent case and default .

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.