473,399 Members | 3,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

php loops how to use a for loop or while loop

Hello Everyone

this is the code
Expand|Select|Wrap|Line Numbers
  1. $a=1;
  2. $b=1;
  3. while($a<=5)
  4. {        
  5.     while($b<=20)
  6. {
  7.  echo $b
  8. }
  9. $b++;
  10. }
  11. $a++;
  12. }
and i want to print
1 1
1 2
1 3
1 4
2 5
2 6
2 7
2 8
3 9
3 10
3 11
3 12
4 13
4 14
4 15
4 16
5 17
5 18
5 19
5 20
Mar 26 '14 #1
1 1047
ariful alam
185 100+
Hello,
There are some mistakes in your code. The correct code is below. This will generate correct answer.
Expand|Select|Wrap|Line Numbers
  1. $a=1;
  2. $b=1;
  3. $i=0;
  4. while($a<=5){
  5.     while($i < 4){
  6.         echo $a . ' ' . $b . '<br/>';
  7.         $b++;
  8.         $i++;
  9.     }
  10.     $a++;
  11.     $i = 0;
  12. }
  13.  
Regard

Happy coding :)
Mar 26 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

24
by: Andrew Koenig | last post by:
PEP 315 suggests that a statement such as do: x = foo() while x != 0: bar(x) be equivalent to while True:
6
by: John Pass | last post by:
What is the difference between a While and Do While/Loop repetition structure. If they is no difference (as it seems) why do both exist?
3
by: libsfan01 | last post by:
hi all in my js code i have a while loop contained within a while loop executed on the basis of a conditional if statement, what i want to do is end the entire function on the last execution on...
3
by: monomaniac21 | last post by:
hi all i have a script that retrieves rows from a single table, rows are related to eachother and are retrieved by doing a series of while loops within while loops. bcos each row contains a text...
14
by: Jan Schmidt | last post by:
Hi, in a nested do-while-loop structure I would like to "continue" the outer loop. With goto this should be no problem in while-loops. However, for do-while I cannot get it to work (without a...
15
by: Synapse | last post by:
I really need your help everyone. i need a program that results the output below using for, while, and do-while loop..3 program codes using those 3 loops...please..i really need your help. Output:...
1
by: somenath | last post by:
Hi All, I have doubt regarding how compiler understands about while loop. For example the bellow mentioned code produce the output as mentioned bellow. #include<stdio.h> int main(void) {
0
by: Marc Vangrieken | last post by:
Hi I have a really weird problem... I'm using some .NET assemblies in classic ASP pages (VBScript) through COM. To make it short; i have some methods and they all return an instance of...
1
by: DennyLoi | last post by:
Hi there I am writing a simple while loop which terminates on the condition that a certain value is found, as follows std::string question = q.quest().que(); std::string answer =...
2
by: troled1 | last post by:
I hace3 a script that needs to write to a mysql database after pulling records from an ACCESS database. The select there are three loops, one outer loop gets the region, the next gets each building...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.