Recent

recentposts

Jump Statement and Nested if or loops

 Jump Statement and Nested if or loops

Jump Statement

Jump Statement unconditionally transfer program control . The various type of jump statements are break , continue , etc.

Break Statement enables a program to skip over some part of the code. It terminates the smallest enclosing like if, for, while, do-while, switch, etc.

Continue Statement enables a program to skip over some part of the code but it does not focus on termination , it forces the next iteration of the loop to take place .

exit(0) is a predefined function used to exit the program whenever it gets executed .

goto label is also a jump statement which transfer the program to the label part of program .

Ex- 

int numb ;


label :

cout<<"\n Enter a number  = " ;

cin>>numb ;


if ( numb != 5 )

 {  goto label ;}


cout<<" Now execute this " ;


In the above program, if the number entered by the user is not equals to 5 , then , the goto statement will transfer the user to the label part and then execute the program. That means the cout written at the end will be executed if the user enter the value of numb as 5 . 



Nested if  means using another if statement inside the body of a if statement .

Syntax :

if ( condition1 )

    {   if ( condition2 )

    {  statement to be executed ;  }

   }

Nested loop  means using another loop statement inside the body of a loop statement .

Nested for  means using another for statement inside the body of a for statement .

Syntax :

for(initialization-expression1 ; test-condition1 ; update-expression1)

  {    body of above loop ;

          for(initialization-expression2 ; test-condition2 ; update-expression2)

          {   body of internal loop ;

 statement to be executed  ;    }

  }





_______________________________________________________

SHARE

Milan Tomic

Hi. I’m Designer of Blog Magic. I’m CEO/Founder of ThemeXpose. I’m Creative Art Director, Web Designer, UI/UX Designer, Interaction Designer, Industrial Designer, Web Developer, Business Enthusiast, StartUp Enthusiast, Speaker, Writer and Photographer. Inspired to make things looks better.

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment

Please give your valuable suggestions