Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Print a Sequence | PHP Loops: for, while, foreach
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
PHP Loops & Iteration

bookChallenge: Print a Sequence

Task

Swipe to start coding

Write a PHP function that prints all even numbers from 2 to 20, each on a new line.

  • Use a for loop to generate numbers from 2 to 20.
  • Check that each number is even.
  • Print each even number on a new line.

Solution

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 2
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

close

bookChallenge: Print a Sequence

Swipe to show menu

Task

Swipe to start coding

Write a PHP function that prints all even numbers from 2 to 20, each on a new line.

  • Use a for loop to generate numbers from 2 to 20.
  • Check that each number is even.
  • Print each even number on a new line.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 2
single

single

some-alt