Results 1 to 6 of 6

Thread: How to create While Loops in PHP?

  1. #1
    Join Date
    Aug 2006
    Posts
    139

    How to create While Loops in PHP?

    I have just started with PHP. I am just completed some basic things in the PHP. Now I got some work that is having the conditions. I guess that there should be something like While Loops, like the other programming languages. But I don't know how to use that. Anyone can tell me how to use While Loops in PHP? Please give me the appropriate solutions and as soon as possible, so that I can finish my work quickly. Also, Extremely Thanks for giving time for solving my problem.!! (In Advance)
    The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little.
    -Joe Martin

  2. #2
    Join Date
    Nov 2008
    Posts
    996

    Re: How to create While Loops in PHP?

    I think that the while loops are the simplest type of loop in PHP. If you have done the C programming language and if you have used the while loop in that, then you can understand the concept immediately. Because there is not much difference in that. The while loop behave just like their C counterparts. The basic form of a while statement is :
    Code:
    while (expr)
        statement
    Hope that you can do more R & D on your own.!

  3. #3
    Join Date
    Nov 2008
    Posts
    1,192

    Re: How to create While Loops in PHP?

    I am trying to tell you in more easier way. The while loop tells PHP to execute the nested statement(s) repeatedly, as long as the while expression evaluates to TRUE. Its similar like you have used the while loop in C or C++ programming language. The value of the expression is checked each time at the beginning of the loop, so even if this value changes during the execution of the nested statement, execution will not stop until the end of the iteration. Like with the if statement, you can group multiple statements within the same while loop by surrounding a group of statements with curly braces, or by using the alternate syntax, just like this one :
    Code:
    while (expr):
        statement
        ...
    endwhile;

  4. #4
    Join Date
    Mar 2008
    Posts
    349

    Re: How to create While Loops in PHP?

    Follow the below steps for creating While Loop in PHP :
    1. First you will have to define the variables you will use and assign them an initial value like :
      Code:
      $count = 1;
      $total = 10;
    2. Then define the condition that is to be checked. For example
      Code:
      while ($count <= 8)
    3. Define the actions to be taken while the condition is still true:
      Code:
      {
      $total = $total + $count;
      echo "The total amount is $total ";
      $count++;
      }

  5. #5
    Join Date
    Jul 2006
    Posts
    289

    Re: How to create While Loops in PHP?

    I have provided you with an example that will define a loop that starts with i=1. The loop will continue to run as long as i is less than, or equal to 7. The variable i will increase by 1 each time the loop runs. Here is a coding for this example :
    Code:
    <html>
    <body>
    
    <?php
    $i=1;
    while($i<=7)
      {
      echo "The number is " . $i . "<br />";
      $i++;
      }
    ?>
    
    </body>
    </html>
    The output of the above coding will be :
    Code:
    The number is 1
    The number is 2
    The number is 3
    The number is 4
    The number is 5
    The number is 6
    The number is 7
    Signatures reduce available bandwidth

  6. #6
    Join Date
    Aug 2006
    Posts
    235

    Re: How to create While Loops in PHP?

    I thought that providing you with an example of printing the decimal number will be more useful. You can print decimal number through 1.0 to 7.0 with PHP While Loop. So here is an example of coding for the same :
    Code:
    <?php
    
    $i = 1.0;
    while ($i <= 7.0 )
    {
    	printf("%.1f<br>", $i);
    
    	$i = $i + 1.0;
    }
    
    ?>
    The above coding will print the decimal number through 1.0 to 7.0
    3.2 (northwood)
    2gig ram
    ATI AIW X800xt 256mb
    Gigabyte GA-8knxp 875p Chipset
    Optiwrite 8X DVD Burner
    Win XP PRO Sp2 (Works Perfectly)
    2 SATA Raptor 74gig Raid 0
    2 7200 IDE 320gig HD

Similar Threads

  1. Bhajis Loops compatibility with Mac
    By Adamaris in forum Windows Software
    Replies: 5
    Last Post: 08-02-2010, 10:11 AM
  2. Flash ActionScript loops
    By Aman 1 in forum Software Development
    Replies: 3
    Last Post: 15-12-2009, 08:06 AM
  3. What does nested loops means?
    By Zhankana_n in forum Software Development
    Replies: 5
    Last Post: 27-11-2009, 11:18 AM
  4. Program to break out of multiple loops
    By Jaheel in forum Software Development
    Replies: 3
    Last Post: 24-11-2009, 12:59 PM
  5. I want a CD of 'Inner Loops'
    By Solaris in forum Portable Devices
    Replies: 5
    Last Post: 09-07-2009, 04:35 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,716,465,742.27042 seconds with 17 queries