Page 1 of 1

Skip 2 digits after print 2 digits

Posted: Tue Jul 20, 2010 1:58 pm
by anaspk
hi,
i need a php code which work in such a way that it skip 2 digits after printing 2 digits:
example:

1,2, 5,6, 9,10, 13,14.........

i now some for looping techniques will do this but don't know hoe please help me

Re: Skip 2 digits after print 2 digits

Posted: Tue Jul 20, 2010 2:33 pm
by AbraCadaver
Many ways:

Code: Select all

for($i=0; $i<=100; ($i % 2 == 0) ? $i+=2 : $i) {
	echo ++$i . ',';
}

for($i=0; $i<=100; ($i % 2) ? $i : $i+=2) {
	echo ++$i . ',';
}

for($i=0; $i<=100; !($i % 2) ? $i+=2 : $i) {
	echo ++$i . ',';
}

for($i=1; $i<=100; $i++) {
	echo $i . ',';
	$i = ($i % 2 == 0) ? $i+=2 : $i;
}