randymartin Posted October 10, 2012 Share Posted October 10, 2012 Hey everybody, For my school i have to fix these following assingments 1 22 333 4444 55555 and this one 11111 2222 333 44 5 i now you need a loop for this and counting down but i am really stuk Quote Link to comment Share on other sites More sharing options...
matthewtbaker Posted October 10, 2012 Share Posted October 10, 2012 Ok i've done the first half for you... <?php for ($count = 1; $count <= 5; $count +=1) { for ($i = 1; $i <= $count; $i ++) { echo $count; } echo "<br />"; } ?> Considering it's school work might be best for you to try and resolve the second half yourself. Matt Quote Link to comment Share on other sites More sharing options...
randymartin Posted October 10, 2012 Author Share Posted October 10, 2012 Ok i've done the first half for you... <?php for ($count = 1; $count <= 5; $count +=1) { for ($i = 1; $i <= $count; $i ++) { echo $count; } echo "<br />"; } ?> Considering it's school work might be best for you to try and resolve the second half yourself. Matt Thanks m8 i will try to fix it many thanks Quote Link to comment Share on other sites More sharing options...
matthewtbaker Posted October 10, 2012 Share Posted October 10, 2012 (edited) Thanks m8 i will try to fix it many thanks No worries. The first for statement is the one which will need to be changed. Basically set the loop count to the maximum loops you require. Then set the lowest times to loop (1) and then set the final variable to deduct 1 each time instead of add 1. It will end up looking like; for ($count = 5; $count >= 1; $count -=1) { That's it. Just make sure you comment your code and give the variables valid names or they'll wonder how you did it... Edited October 10, 2012 by matthewtbaker Quote Link to comment Share on other sites More sharing options...
randymartin Posted October 10, 2012 Author Share Posted October 10, 2012 No worries. The first for statement is the one which will need to be changed. Basically set the loop count to the maximum loops you require. Then set the lowest times to loop (1) and then set the final variable to deduct 1 each time instead of add 1. It will end up looking like; for ($count = 5; $count >= 1; $count -=1) { That's it. Just make sure you comment your code and give the variables valid names or they'll wonder how you did it... youre awesome, i am doing ict, aducation but first six week is an introduction for people that would like to chose application development and since i am so bad at php it is not for me, but you have to make the assignments still got 2 left i have to make this one, 1 23 345 4567 56789 i really have no idea how you can make it haha Quote Link to comment Share on other sites More sharing options...
Barand Posted October 10, 2012 Share Posted October 10, 2012 Shouldn't be too hard to spot there is a definite pattern there Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 10, 2012 Share Posted October 10, 2012 1 23 345 4567 56789 i really have no idea how you can make it haha Start by creating a description of the rules for the pattern as you would describe to another human. Then figure out how you will do it in the code. In this case I would describe it as follows: Starting with the number 1, perform the following process for 5 iterations: On each iteration create a number that 1) starts with the digit matching the iteration count 2) contains sequentially numbered digits up to the same number as the iteration count Quote Link to comment Share on other sites More sharing options...
matthewtbaker Posted October 19, 2012 Share Posted October 19, 2012 How did you get on? Solved? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.