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 complier to reach the end of the block of statemnts of the loop , i.e skipping all the statemnts 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 ull 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 didnt executed 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 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 statment in the loop the  goto statemnt 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 statemnt until a condition is reached where the goto statment is not used . and then it comes out of the loop

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

 

 

NO COMMENTS