UnConditional And Loop Control Statements of C Language Part-2

do-while loop

UNCONDITIONAL CONTROL STATEMENT:
  • C supports an unconditional control statement that is goto. 
  • goto is used to transfer control from one point to other in a C program.
  • Goto is a branching statement.
  • It requires a label. 
  • goto is a keyword.

The syntax of goto statement is:


 goto  END:  
 ................
 ................
 ................ 
 END:
.................


Points to remember about goto statement:
  1. goto statement is used whenever necessary else should be avoid.
  2. goto statement create an infinite loop.
  3. Any number of goto statements used in C program.
  4. No two goto statements have the same label name.
NOTE: Lable can be placed either before or after the goto statement.

LOOP CONTROL STRUCTURE:
Three types of loop control structures are used in C language.
  1. While Loop
  2. Do-while Loop
  3. For Loop
While Loop:
This is used to execute a set of statements repeatedly as long as the condition is TRUE.The syntax of While Loop is:



 while(condition) 
         {
   statement;
         } 
Where
Statement => simple or compound statement
while => keyword
Condition => results in TRUE or FALSE


Explanation:  If the logical condition is TRUE then the statement is repetedly executed. If the result is FALSE then control comes out of the loop and continues with the next executable statement.The value of variable involved in the logical condition will be changed during every pass of while loop. If the value does not changed then control does not come out of the loop and statements executed repeatedly that is infinite loop.

Example:
int a=0;
while(a<5)
{
printf(" the value of a is=%d/n" , a);
a++;
}

Output:
Value of a=1
Value of a=2
Value of a=3
Value of a=4

Do-while Loop:
This is used to execute a set of statements repeatedly,untill the logical test results in FALSE.The syntax of Do-while Loop is:


  do
  {
  statement;
  } while(condition); 


Explanation: If the logical condition is TRUE then the statement is repetedly executed. If the result is FALSE then control comes out of the do-while loop and continues with the next executable statement.

For Loop:
It is used when the programmer knows how many times a set of statements are to be executed. The syntax of for loop is:




 for ( exp1; exp2; exp3) 
 {
 statement;
 }


Where
Exp1 => assign the value to variable.
Exp2 => give condition to variable.
Exp3 => increment or decrement in the value of variable.
Statement => compound or simple statement
for => keyword
 

Example:
for  (i=8 ; i>4 ; i--)
{
printf("value of i=%d/n" , i);
}

Output:

Value of i=8
Value of i=7
Value of i=6
Value of i=5



0 Response to "UnConditional And Loop Control Statements of C Language Part-2"

Post a Comment

Popular Posts

Label

1 Sidebar 2 Columns 3 Columns Footer 3rdball 4 Columns Footer Alex Alvaro Antsasia Arlinadesign Averie Barry BASIC CONCEPTS Basil Bayna Fast BeautyPress BeautyTemplates Beckel Best Best - Clean Beyonce Pro BioMag BlackMag Blanter Nova Blogger Card Bloggertheme9 Blogish Bpress Brakt C LANGUAGE C PROGRAMS C++ LANGUAGE C++ PROGRAMS Carella Cellar Charlotte Chooko Lite Clara Clean Combo One Cooperate Crusade Darry Dorman Dreamway Dunia Blanter eCars EduAcademy EducationPress Elise Elvan Eva Everyday FabNews Fashion Fashion Blogger Template Fashion Gossip FastCars Fedo FlashNews Fredy Portfolio Gaming Globus GoodTime Goomsite HTML LANGUAGE iGaming Indicate Innove Insomnia InspiredNews iSoft Jasmine Kalem Landscaping Lashira Lavelle Lily Fashion Limax Linea Lionex Luminescence Lite Lumix Luxury Magazine MagazinePro MAJOR DIFFERENCES MarketingBlog Martin MaxiMag Medica Mega Melissa Mercury MeshMag Minimag Minimalist MiniNews MovieKhor msdesignbd MusicLand Neko NetZine New Spread News16 Newsflash NewsForce NewsIdea Newspaper News NewsPro Nubie Fast Odd Themes Optima PaperMag PaperMag blog Parhlo Perfection Personal Personal Blog Photosout PixelZ Power Blog Premium Themes ProfileMag Purez Rano ReadNews Real estate Remito Grid Responsive Revo Robusta Rotario Saara SeoBoost Settle Shouters Simple Catch SimpleClean Sketchly SNews SolidMag Someo Sophie Sora Sora Bank Sora Home Sora News Responsive Sora One Sora Ribbon Spido Sticko Stucco Sure Mag Swift Tech Tech Pro Techia Techmax TechSpot TemplateClue Templateism Templatesilk Templatesyard Templatezy The Freelancer TheBlogger TheFocus Themeforest Themexpose TIPS AND TRICKS Topside TravelMag Trendy Trendy Travel Tumblr Under Construction Uong Jowo Veethemes Vertox VideoPlay Vigo Waverly way2themes WebBiz Wedding X-Mag Zealer ZetaMag