Ketan Kore
Sunbeam Infotech
Sunbeam Infotech www.sunbeaminfo.com
Control Statements
• Decision or Selection
• if-else
• switch-case
• Iteration (loop)
• for
• while
• do-while
• Jump
• break
• continue
• goto
• return
Sunbeam Infotech www.sunbeaminfo.com
break/continue
• break statement
• Used to early exit from loop, or to exit an infinite loop
• Takes control out of current loop and continues execution of statements after the loop.
• Statements after break are skipped.
• continue statement
• Used to continue next iteration of the loop.
• Statements after continue are skipped (for current iteration).
• break is used with loop/switch case.
• continue used with only loop.
• In case of nested loops, break/continue affects current loop only (not outer).
Sunbeam Infotech www.sunbeaminfo.com
Functions
• C program is made up of one or more functions.
• C program contains at least one function i.e. main() function.
• Execution of C program begins from main.
• It returns exit status to the system.
• Advantages
• Reusability Function
• Readability
• Maintainability
• Function is set of instructions, that takes zero or more inputs (arguments) and return
result (optional).
• Function is a black box.
Sunbeam Infotech www.sunbeaminfo.com
Functions
• Each function has
• Declaration
• Definition
• Call
• A function can be called one or more times.
• Arguments Examples:
1. addition()
• Arguments passed to function Actual arguments 2. print_line()
• Arguments collected in function Formal arguments 3. factorial()
• Formal arguments must match with actual arguments 4. combination()
Sunbeam Infotech www.sunbeaminfo.com
Function execution
• When a function is called, function
activation record/stack frame is
created on stack of current process.
• When function is completed, function
activation record is destroyed.
• Function activation record contains:
• Local variables
• Formal arguments
• Return address
• Upon completion, next instruction after
function call continue to execute.
Sunbeam Infotech www.sunbeaminfo.com
Thank you!
Ketan Kore<Ketan.Kore@sunbeaminfo.com>
Sunbeam Infotech www.sunbeaminfo.com