Session 05 Introduction to Programming

22 185 0
Session 05 Introduction to Programming

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Differentiate between Command, Program and SoftwareExplain the beginning of CExplain when and why is C usedDiscuss the C program structureDiscuss algorithmsDraw flowchartsList the symbols used in flowcharts

LBC, Session 5 Loop FPT APTECH COMPUTER EDUCATION HANOI Objectives • • • • 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 LBC/Session 5 2 What is a Loop? Section of code in a program which is executed repeatedly, until a specific condition is satisfied LBC/Session 5 3 3 types of Loop Structures The for loop The while loop The do….while loop LBC/Session 5 4 The for loop-1 Syntax: for(initialize counter; conditional test; re valuation) { statement } •The initialize counter is an assignment statement that sets the loop control variable, before entering the loop •The conditional test is a relational expression, which determines, when the loop will exit •The evaluation parameter defines how the loop control variable changes, each time the loop is executed LBC/Session 5 5 The for loop-2 • 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 LBC/Session 5 6 The for loop-3 void main() { int count; printf("\tThis is a \n"); for(count = 1; count [...]... used to return from a function •It causes execution to return to the point at which the call to the function was made •The return statement can have a value with it, which it returns to the program LBC /Session 5 16 Jump Statements-2 goto label; •The goto statement transfers control to any other statement within the same function in a C program •It actually violates the rules of a strictly structured programming. .. reliability and make program difficult to maintain LBC /Session 5 17 Jump Statements-3 Break; •The break statement is used to terminate acase in a switch statement •It can also be used for abrupt termination of a loop •When the break statement is encountered in a loop, the loop is terminated immediately and control is passed to the statement following the loop LBC /Session 5 18 Jump Statements-4 void main... will be terminated, and the control goes to the statement that appears immediately after the while statement LBC /Session 5 14 do…while Loop-2 void main() { int num1, num2; num2 = 0; Example do { printf( "\nEnter a number : "); scanf(“%d”,&num1); printf( " No is %d",num1); num2++; } while (num1 != 0); printf ("\nThe total numbers entered were %d", num2); } LBC /Session 5 15 Jump Statements-1 return expression;... ",count2); scanf("%d", &count2); if(count2==100) break; } } LBC /Session 5 19 Jump Statements-5 continue; •The continue statement causes the next iteration of the enclosing loop to begin •When this statement is encountered, the remaining statements in the body of the loop are skipped and the control is passed on to the reinitialization step LBC /Session 5 20 Jump Statements-6 void main() { Example int num;... k++) { printf("*"); } } } LBC /Session 5 11 The while Loop-1 Syntax: while (condition is true){ statement ; } The while loop repeats statements while a certain specified condition is True LBC /Session 5 12 The while Loop-2 void main() Example { int count = 1; while( count ... Understand the exit() function LBC /Session What is a Loop? Section of code in a program which is executed repeatedly, until a specific condition is satisfied LBC /Session 3 types of Loop Structures... for loop LBC /Session The for loop-3 void main() { int count; printf(" This is a "); for(count = 1; count

Ngày đăng: 08/10/2015, 22:23

Mục lục

  • LBC, Session 5

  • Objectives

  • What is a Loop?

  • 3 types of Loop Structures

  • The for loop-1

  • The for loop-2

  • The for loop-3

  • The Comma Operator

  • Slide 9

  • Nested for Loops-1

  • Nested for Loops-2

  • The while Loop-1

  • The while Loop-2

  • do…while Loop-1

  • do…while Loop-2

  • Jump Statements-1

  • Jump Statements-2

  • Jump Statements-3

  • Jump Statements-4

  • Jump Statements-5

Tài liệu cùng người dùng

Tài liệu liên quan