need help with simple for loop new to PHP and forum Read mo
Moderator: General Moderators
need help with simple for loop new to PHP and forum Read mo
I need to figure out how to make 5 rows of * and only use one for loop it has been driving me nuts all week any help is greatly appreciated because I have tried so many different ways. I am trying to create this but with only one for loop in php
*
**
***
****
*****
*
**
***
****
*****
Re: need help with simple for loop new to PHP and forum Rea
What was your best attempt? I bet it doesn't need much work to get it working correctly.
Re: need help with simple for loop new to PHP and forum Rea
for($i=0; $i<5; $i++){
echo "*";
}
echo "*";
}
Re: need help with simple for loop new to PHP and forum Rea
That will print exactly five stars and only once.
You need another loop that counts how many stars should be outputted per line, from one star to five stars. The loop you have now should count to that number instead of always going to five.
You need another loop that counts how many stars should be outputted per line, from one star to five stars. The loop you have now should count to that number instead of always going to five.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: need help with simple for loop new to PHP and forum Rea
And I bet if you looked in the manual in the string functions you could find a function that would repeat a character N times.
(#10850)
Re: need help with simple for loop new to PHP and forum Rea
ak4744710 wrote:and only use one for loop
Doesn't fit the assignments requirements (sorry, this really seems like an assignment for a programming class)requinix wrote:You need another loop
Christopher is right on about the route to take, learn the functions here: http://www.php.net/manual/en/ref.strings.php
Re: need help with simple for loop new to PHP and forum Rea
My bad. Saw the stars, thought it was a "learning how to use loops" assignment.twinedev wrote:Doesn't fit the assignments requirements
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: need help with simple for loop new to PHP and forum Rea
Uh oh ... requinix is seeing stars and acting loopy!requinix wrote:My bad. Saw the stars, thought it was a "learning how to use loops" assignment.twinedev wrote:Doesn't fit the assignments requirements
(#10850)
Re: need help with simple for loop new to PHP and forum Rea
Can you post the codes? I just want to compare it to my work.
Thanks
Thanks