Return Break and Continue Statements, Embedded programming Tutorial Chapter 4

This is the 4th chapter of Embedded programming tutorial. For other chapters please go to the links provided in the last portion of this page. In this chapter we are dealing with return break and continue statements.

If you are interested to do Machine learning (Embedded system) course through online, with certification and proper placement log on to Udacity (use this link for sign up, thus you get 1000 rs discount in your first enrolment).

While writing C program we require to terminate the program or even to continue the same statements like return break and continue. helps us to do this. let’s see how they can be used in our programs effectively.

Return Statement

The return statement terminates the execution of a function and returns control to the calling function. Execution resumes in the calling function at the point immediately following the call. A return statement can also return a value to the calling function. A return statement causes execution to leave the current subroutine and resume at the point the subroutine was called.

Break Statement 

In this example the main function returns values 0 to the operating system. As operating system has called the main function. a break statement.

lets you end an iterative DO, FOR, WHILE statement. Break statement is also essential to switch statement for
exiting from a case. In the sample program WHILE LOOP is running based on an infinite condition. the infinite
condition will keep WHILE LOOP running forever. We have added one IF statement to check if value of variable t becomes 40. If it equals to 40 the program will terminate the WHILE LOOP. Remember again that the break statement will terminate the WHILE LOOP.

Continue Statement

A continue statement ends the current iteration of a loop program.

 Here control is passed from the continue statement to the end of the loop body. Let’s take a simple task. We will write a program which will do something if the temperature is not equal to 45. This program is running an endless WHILE LOOP Inside the WHILE LOOP. we are reading temperature value. If the temperature value equals to 45 then all further statements will be skipped. In other words blow horn will not get executed if temperature becomes 45. Use continue statement to skip the execution of statement inside the loops.

You have finished the first stage of learning C language. The C applications can be written and compiled using turbo C software. Turbo C software is a combination of source code editor and compiler. You can write C programs using turbo C. These C programs can only work with your computer. They will not work with your microcontroller or any embedded device.

Click here for next chapter 

Click here for Previous chapters

Embedded C programming Tutorial : click below links to learn more

chapter 1         chapter 2        chapter 3        chapter 4        chapter 5      Chapter 6

chapter 7

 

Comments

comments