Jump to content

[SOLVED] Even and uneven numbers


JJohnsenDK

Recommended Posts

As has been said, this:

 

<?php



for ($i = 0;$i <= 30; $i++) {
if($i % 2) {
echo "$i is an odd number <br>";
} else {
echo "$i is an even number <br>";
}
}
?>

 

will echo

 

0 is an even number
1 is an odd number
2 is an even number
3 is an odd number
4 is an even number
5 is an odd number
6 is an even number
7 is an odd number
8 is an even number
9 is an odd number
10 is an even number
11 is an odd number
12 is an even number
13 is an odd number
14 is an even number
15 is an odd number
16 is an even number
17 is an odd number
18 is an even number
19 is an odd number
20 is an even number
21 is an odd number
22 is an even number
23 is an odd number
24 is an even number
25 is an odd number
26 is an even number
27 is an odd number
28 is an even number
29 is an odd number
30 is an even number

 

Sam

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.