Wednesday, 15 January 2014

Fizz Buzz script using while loop stuck in infinite loop - php -


I try to write a buz slip through the cycle through a while loop numbers I am 1-100 and resonance every one on the screen

I am using the modulus operator to detect a module:

  • 3 in which case it is fissose,
  • 5, in which case this buff,
  • or if both of these both 3 and 5 have a multiple Echos FizzBuzz

    I have written the code below, all of them Parts have been tested and it seems to work, but when I run the script, it gets trapped in an infinite loop, Fiz .

      $ i = 1; While ($ i & lt; = 100) {if ((3% $ i) === 0) {echo 'fish'; $ I = $ i ++; } And if ((5% $ i) === 0) {$ i = $ i ++; Echo 'buz'; } And if (((3% $ i) === 0) & amp; ((5% $ i) === 0)) {echo 'FizzBuzz'; } Else {echo $ i ++; }}   

    Was anyone wrong?

      $ i = 1; While ($ i & lt; = 100) {$ r = ''; If ($ i% 3 === 0) {$ r = 'Fitz'; } If ($ i% 5 === 0) {$ r = 'Buzz'; } If (! $ R) {$ r = $ i; } Repeat "$ r \ n"; ++ $ i; }   

    Online demo:

No comments:

Post a Comment