Author Topic: for loop, while loop syntax  (Read 880 times)

administrator

  • Administrator
  • Full Member
  • *****
  • Posts: 69
for loop, while loop syntax
« on: October 26, 2011, 10:58:56 am »
for loop has 3 parts separated by semicolon (;). All fields are optional, but two semi colons are mandatory.

1. initial assignment - executed only one before entering the for loop
2. Condition - evaluated after executing loop each and every time.
3. Increment - incremented after executing loop each and every time.

example: The for loop will be executed 10 times.

for(int i = 0; i < 10; i++)
{
}

example: The following example is infinite for loop
for( ; ; )
{
}


While loop only one part that is condition.
example:
while(1)
{
   // do something in infinite for loop
}

Usefull Links:

http://www.softwareandfinance.com/Turbo_C/Loops_Disp_Number.html

http://www.softwareandfinance.com/Turbo_C/Loops.html


« Last Edit: October 26, 2011, 11:03:34 am by admin softwareandfinance »

 


Disclaimer: This web site is for educational and informational purposes only. Click here to read the Disclaimer.
Content copyright 2010-2014. Kathiresan. All rights reserved.
This page is using SMF version 2.0.1