Building the Loop

Author Topic: Building the Loop  (Read 478 times)

Offline chinmay.sahooTopic starter

  • Trade Count: (0)
  • Full Member
  • ***
  • Thank You 2
  • Posts: 139
  • Karma: 0
    • No Addiction
Building the Loop
« on: 05-14-2016, 04:06:11 »
Once you’ve set up the parts of the for statement, the loop itself is easy to use. Place braces ({}) around your code and indent all code that’s inside the loop. You can have as many lines of code as you wish inside a loop, including branching statements and other loops.
The sentry variable has special behavior inside the loop. It begins with the initial value.

Each time the loop repeats, it is changed as specified in the for structure, and the interpreter checks the condition to ensure that it’s still true. If so, the code in the loop occurs again. In the case of the basicArray program, $i begins as 0. The first time the print statement occurs, it prints 0 because that is the current value of $i. When the interpreter reaches the right brace that ends the loop, it increments $i by 1 (following the $i++ directive in the for structure) and checks the condition ($i < 10). Because 0 is less than 10, the condition is true and the code inside the loop occurs again. Eventually, the value of $i becomes 10, so the condition ($i < 10) is no longer true. Program control then reverts to the next line of code after the end of the loop, which ends the
Although the sentry variable is an ordinary variable, it should not be changed inside the loop.
Let the for loop instructions do all the work.


Related Topics

  Subject / Started by Replies Last post
5 Replies
Last post 04-16-2012, 03:08:49
by Socialmarketing
0 Replies
Last post 04-19-2012, 15:27:16
by SEO Español
2 Replies
Last post 01-10-2013, 23:29:05
by onefor1two
0 Replies
Last post 06-10-2015, 06:16:48
by KL76
2 Replies
Last post 03-17-2016, 23:16:38
by RH-Calvin