Skip to content

Instantly share code, notes, and snippets.

@malikalichsan
Last active June 18, 2020 06:40
Show Gist options
  • Save malikalichsan/1a501f1734fba2848fec170e55ae1c03 to your computer and use it in GitHub Desktop.
Save malikalichsan/1a501f1734fba2848fec170e55ae1c03 to your computer and use it in GitHub Desktop.
Basic looping using Dragon Ball as example in PHP
<?php
class DragonBall {
public $ballCount = 0;
public function iFoundBall($loop) {
for ($i = 0; $i < $loop; $i++) {
$ball = $this->ballCount+=1;
echo 'Ball ' . $ball . ' ';
if ($this->ballCount == 7) {
echo 'Ho Ho Ho, I\'m Shenron, You can ask your wish';
exit;
}
}
$this->ballCount = 0;
}
}
$dragonBall = new DragonBall;
echo $dragonBall->iFoundBall(8); // You can try to change the parameter
// THIS IS THE OUTPUT
// Ball 1 Ball 2 Ball 3 Ball 4 Ball 5 Ball 6 Ball 7 Ho Ho Ho, I'm Shenron, You can ask your wish
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment