Lets continue with the statements ….

Continue statement

Continue statement leads to the end of the current iteration and leads to the new iteration. It allows the compiler to reach the end of the block of statements of the loop, i.e skipping all the statements in the loop , hence end the current iteration and leads to start the new iteration.

EXAMPLE
continue-statements

continue-statement

 

here in this example again we have used for loop and output without a continue should have been

0

1

2

3

4

5

6

but if you’ll notice it carefully “3” is missing , it is because in continue the control goes to the starting of the loop .Similar happened in our case as soon as it encountered a continue it didn’t execute the next statement rather it went to  the start of the loop to continue its execution.

Goto statement

Goto allows you to jump from one part of the code to another. All this is done via labels . Since it makes unconditional jumps so utmost care should be taken try to use this in local block.

label in C-Programming:

Label can be defined as label: i.e it can be anything word letter and you can even use numbers eq L1 but it should always end with a colon (:) .

consider the following example

EXAMPLE
goto--statements
goto-statements

here   in this example goto statement is used .Here if goto statement was absent then the output would have been ..

5

4

3

2

1

0

but goto statement is used here hence when the loop counter goes to 3 then due to if statement in the loop the  goto statement is executed and it searches for its label that is in our case l1. Now when the label is found then the flow of control of the program shifts to the statement ” cout<<“enter a number”; “ and it continues the execution of program from that statement until a condition is reached where the goto statement is not used. and then it comes out of the loop

The rest of the topic is discussed in the next post.

Have something to add in Statements-2: Nested if-else and break statements ? Share/Ask into comments it in the comments.

Follow us on Facebook, Google Plus and Twitter

Previous                                      C Programming                                      Next

NO COMMENTS